Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. Your task is to write a Python program that encrypts or decrypts a given text into/from a secret language.
  2.  
  3. Individual words in the text are encrypted according to the following rules:
  4.  
  5. If the word starts with a vowel append 'tan' to the word. The vowels are a, e, i, o, u.
  6. Otherwise, take the first letter of the word, move it to the end and then append 'est'.
  7. So:
  8.  
  9. apple becomes appletan
  10. orange becomes orangetan
  11. banana becomes ananabest
  12. python becomes ythonpest
  13. For simplicity we'll assume that the input text is in lowercase and that it does not contain any punctuation (no commas, periods, etc...)
  14.  
  15. 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).
  16.  
  17. 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.
  18.  
  19. 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.
  20.  
  21. Testing:
  22. 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.
  23.  
  24. Test case 1 - encryption is correct for words starting with a vowel
  25. Please type E to encrypt or D to decrypt a message: E
  26. Please enter your message: apple
  27. The secret message is: appletan
  28.  
  29. Test case 2 - encryption is correct for words starting with a consonant (non vowel)
  30. Please type E to encrypt or D to decrypt a message: E
  31. Please enter your message: banana
  32. The secret message is: ananabest
  33.  
  34. Test case 3 - encryption is correct for phrases with multiple words
  35. Please enter your message: python is fun
  36. The secret message is: unfest istan ythonpest
  37.  
  38. Test case 4 - encryption is correct when words are separated by more than one space character
  39. Please enter your message: simple is better than complex
  40. The secret message is: omplexcest hantest etterbest istan implesest
  41.  
  42. Test case 5 - decryption is correct for words ending with 'tan'
  43. Please type E to encrypt or D to decrypt a message: D
  44. Please enter your message: orangetan
  45. The secret message is: orange
  46.  
  47. Test case 6 - decryption is correct for words ending with a consonant followed with 'est'
  48. Please type E to encrypt or D to decrypt a message: D
  49. Please enter your message: ryptographycest
  50. The secret message is: cryptography
  51.  
  52. Test case 7 - decryption is correct for phrases with multiple words
  53. Please type E to encrypt or D to decrypt a message: D
  54. Please enter your message: omplexcest hantest etterbest istan implesest
  55. The secret message is: simple is better than complex
  56.  
  57. Test case 8 - The user is repeatedly prompted for input until they enter a valid choice (E or D)
  58. Please type E to encrypt or D to decrypt a message: K
  59. Invalid choice
  60. Please type E to encrypt or D to decrypt a message: x
  61. Invalid choice
  62. Please type E to encrypt or D to decrypt a message: e
  63. Invalid choice
  64. Please type E to encrypt or D to decrypt a message: E
  65. Please enter your message: hello
  66. The secret message is: ellohest
  67.  
  68. Test case 9 - An invalid message is not decrypted
  69. Please type E to encrypt or D to decrypt a message: D
  70. Please enter your message: this is fun
  71. Invalid Message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement