Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. def encode(plaintext):
  2. plaintext = str(plaintext)
  3. cyphertext = ""
  4. count = 0
  5. advancedcyphertext = ""
  6. for l in plaintext:
  7. cyphertext += str(ord(l)) + " "
  8. count += 1
  9. advancedcyphertext += str((ord(l) + count) * 2) + " "
  10. print "== Encodes to =="
  11. return "%s" % (advancedcyphertext)
  12.  
  13. def decode(cyphertext):
  14. cyphertext = str(cyphertext).strip()
  15. count = 1
  16. cypheredtext = []
  17. cyphered = ""
  18. cyphertext = list(cyphertext.split(" "))
  19. for l in cyphertext:
  20. l = (int(l) / 2) - count
  21. count += 1
  22. cypheredtext += [l]
  23. for n in cypheredtext:
  24. cyphered += str(chr(int(n)))
  25. print "== Decodes to =="
  26. return cyphered
  27.  
  28. def runscript():
  29. choice = str(raw_input("Encode or Decode? (e / d): "))
  30. if choice == "e":
  31. plaintext = raw_input("Please type a message to encode:\n")
  32. print encode(plaintext)
  33. return runscript()
  34. elif choice == "d":
  35. plaintext = raw_input("Please type a message to decode:\n")
  36. print decode(plaintext)
  37. return runscript()
  38. else:
  39. print "Sorry, please input the letter e or d..."
  40. print
  41. return runscript()
  42. runscript()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement