Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. # The Finnish death metal band Demilich released an album in 1993 called
  2. # "Nespithe". The liner notes, as well as the album title and one song title,
  3. # are written in code: start at the end of the phrase, group the letters in
  4. # three, and reverse the groups' order.
  5.  
  6. def encode(string):
  7. string = string.replace(" ","")
  8. newstr = ""
  9. for i in range(0,len(string),3):
  10. newstr = string[i:i+3] + newstr
  11. return newstr.upper()
  12.  
  13. def decode(string):
  14. string = string.replace(" ","")
  15. newstr = ""
  16. for i in range(len(string),2,-3):
  17. newstr += string[i-3:i]
  18. newstr += string[0:i%3]
  19. return newstr.upper()
  20.  
  21. fkey = None
  22. while fkey != "q":
  23. function = input("[E]ncode, [D]ecode, or [Q]uit? ")
  24. fkey = function[0].lower()
  25. if fkey == "q":
  26. continue
  27. elif fkey == "e":
  28. string = input("String to encode: ")
  29. print(encode(string))
  30. elif fkey == "d":
  31. string = input("String to decode: ")
  32. print(decode(string))
  33.  
  34. print("Flying out of this world to another land...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement