Guest User

Untitled

a guest
Apr 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. ''' cool Ceasar cypher encryptor/decryptor '''
  2. # made by Jeremy Carder Apr. 15, 2018
  3.  
  4.  
  5. try:
  6. import pyperclip
  7. except ModuleNotFoundError:
  8. pass
  9.  
  10. import random
  11.  
  12.  
  13. mode = ''
  14. alphabet = "abcdefghijklmnopqrstuvwxyz"
  15. output = []
  16.  
  17.  
  18. def cryptor(encrypt):
  19. global output
  20.  
  21. for letter in message:
  22. if letter == ".":
  23. output.append(".")
  24. elif letter == ",":
  25. output.append("")
  26. elif letter == " ":
  27. output.append(" ")
  28. else:
  29. if encrypt:
  30. comb = alphabet.index(letter) + int(shift)
  31. else:
  32. comb = alphabet.index(letter) - int(shift)
  33.  
  34. if comb > 25:
  35. comb -= 26
  36.  
  37. output.append(alphabet[comb])
  38.  
  39.  
  40. print(shift, "".join(output), "\n")
  41.  
  42. if encrypt:
  43. try:
  44. pyperclip.copy("".join(output))
  45. print("(copied to clipboard)")
  46. except:
  47. print("Install the 'pyperclip' Python module to automatically copy encoded message to clipboard.")
  48.  
  49. output = []
  50.  
  51.  
  52. print("Press 'q' to quit.")
  53.  
  54. while mode != 'q':
  55.  
  56. mode = input("\nEnter 'e' to encrypt or 'd' to decrypt: ")
  57.  
  58. if mode != 'q':
  59. message = input("Message: ").lower()
  60. shift = input("Shift (random is default): ")
  61.  
  62. if mode == 'e':
  63.  
  64. if shift == "":
  65. shift = random.randint(0, 26)
  66. cryptor(True)
  67.  
  68. else:
  69.  
  70. if shift == "":
  71. for shift in range(0, 26):
  72. cryptor(False)
  73. else:
  74. cryptor(False)
Add Comment
Please, Sign In to add comment