Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Your task is to write a Python program that encrypts or decrypts a given text into/from a secret language.
- Individual words in the text are encrypted according to the following rules:
- If the word starts with a vowel append 'tan' to the word. The vowels are a, e, i, o, u.
- Otherwise, take the first letter of the word, move it to the end and then append 'est'.
- So:
- apple becomes appletan
- orange becomes orangetan
- banana becomes ananabest
- python becomes ythonpest
- For simplicity we'll assume that the input text is in lowercase and that it does not contain any punctuation (no commas, periods, etc...)
- Your program will first ask the user to make a choice between encryption into the secret language (E) or decryption from the secret language (D).
- When the user specifies 'E' for encryption, the program will translate each word in the input text into the secret language, will put the translated words in reverse order into one translated message and will print out the translated message. The translated message will have exactly one space character between words.
- When the user specifies 'D' for decryption', the program will attempt to recover the original words from the input text. This is only possible if the words have a specific format: they start with a vowel and end with tan or they end with a consonant followed by est. If one or more word does not have this format, the decryption fails and the message 'Invalid Message' is printed.
- Testing:
- Make sure that you test your solution before you submit it. Here are a few test cases with the expected output. Feel free to add your own.
- Test case 1 - encryption is correct for words starting with a vowel
- Please type E to encrypt or D to decrypt a message: E
- Please enter your message: apple
- The secret message is: appletan
- Test case 2 - encryption is correct for words starting with a consonant (non vowel)
- Please type E to encrypt or D to decrypt a message: E
- Please enter your message: banana
- The secret message is: ananabest
- Test case 3 - encryption is correct for phrases with multiple words
- Please enter your message: python is fun
- The secret message is: unfest istan ythonpest
- Test case 4 - encryption is correct when words are separated by more than one space character
- Please enter your message: simple is better than complex
- The secret message is: omplexcest hantest etterbest istan implesest
- Test case 5 - decryption is correct for words ending with 'tan'
- Please type E to encrypt or D to decrypt a message: D
- Please enter your message: orangetan
- The secret message is: orange
- Test case 6 - decryption is correct for words ending with a consonant followed with 'est'
- Please type E to encrypt or D to decrypt a message: D
- Please enter your message: ryptographycest
- The secret message is: cryptography
- Test case 7 - decryption is correct for phrases with multiple words
- Please type E to encrypt or D to decrypt a message: D
- Please enter your message: omplexcest hantest etterbest istan implesest
- The secret message is: simple is better than complex
- Test case 8 - The user is repeatedly prompted for input until they enter a valid choice (E or D)
- Please type E to encrypt or D to decrypt a message: K
- Invalid choice
- Please type E to encrypt or D to decrypt a message: x
- Invalid choice
- Please type E to encrypt or D to decrypt a message: e
- Invalid choice
- Please type E to encrypt or D to decrypt a message: E
- Please enter your message: hello
- The secret message is: ellohest
- Test case 9 - An invalid message is not decrypted
- Please type E to encrypt or D to decrypt a message: D
- Please enter your message: this is fun
- Invalid Message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement