Encryption : The process of converting sensitive information into a code to protect it.
Encryption is one of the most important processes in most systems these days. Keeping data and personal information safe from crackers is of utmost importance and therefore encrypting sensitive data is mandatory. Encryption processes these days are highly advanced but one of the simplest and most well-known forms of encryption is Pig-Latin.
Pig Latin is a simple spoken code that can keep your secrets safe from others. To anyone who doesn't know Pig Latin, the words sound funny but will make complete sense to everyone who understands Pig Latin. A simple Pig Latin translator in Python will be helpful when you need to convert any English word to Pig Latin in seconds, so your secrets remain safe.
Rules of Pig Latin:
- If the word to convert starts with a vowel: Just add '-yay' to the end of the word. Ex. Ant gets converted to Antyay.
- If the word starts with a consonant or a group of consonants: The cluster of consonants are moved to the end of the word and '-ay' is added in the end. Ex. code gets converted to odecay.
- If the word starts with y: y is treated as a consonant. Ex. yes gets converted to esyay
- If the word has y in any position other than the start: y is treated as a vowel. Ex. Python gets converted to ythonpay
#Pig-Latin Translator word = input('Enter a word: ') word_split = [letter.lower() for letter in word] vowel_list = ['a','e','i','o','u'] #Case 1 - Word begins with vowel: if word[0].lower() in vowel_list: translation = word + 'yay' #Case 2 - Word begins with consonant or consonant cluster else: temporary_list = [] for i in range(0,len(word_split)): if word_split[i].lower() not in vowel_list and word_split[i].lower() != 'y': temporary_list.append(word_split[i].lower()) else: break for j in temporary_list: if j in word_split: word_split.remove(j) word_split.extend(temporary_list) translation = ''.join(word_split) + 'ay' print(translation)
Enter a word: Ant Antyay >>>
Enter a word: Python ythonpay >>>
- Make a Pig-Latin translator for paragraphs. Create a function to make the work simpler and use the word.split() function to break down the paragraph into words.
- Try to build a Pig-Latin to English converter. Some small edits to the same code will do the trick.
Comments
Post a Comment