Advertisement
Guest User

encrypt and decrypt

a guest
Oct 13th, 2019
3,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. # Caesar Cipher
  2. # https://inventwithpython.com/hacking (BSD Licensed)
  3.  
  4. import pyperclip
  5. import time
  6. # every possible symbol that can be encrypted
  7. LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+ '
  8. # tells the program to encrypt or decrypt
  9. mode = input("\033[0;32m Enter the mode type : \n 01 : Encrypt \n 02 : Decrypt \n") # set to 'encrypt' or 'decrypt'
  10. if mode == "01":
  11. mode="encrypt"
  12. if mode == "02":
  13. mode="decrypt"
  14.  
  15.  
  16. # The string to be encrypted/decrypted:
  17. message = input("Enter the secret message : \n")
  18.  
  19. # the encryption/decryption key
  20. key = int( input("Enter the key: - \033[0;31m you can't decrypt without the key! \033[0;32m - \n") )
  21.  
  22.  
  23.  
  24.  
  25. # stores the encrypted/decrypted form of the message
  26. translated = ''
  27.  
  28. # capitalize the string in message
  29. message = message.upper()
  30.  
  31. # run the encryption/decryption code on each symbol in the message string
  32. for symbol in message:
  33. if symbol in LETTERS:
  34. # get the encrypted (or decrypted) number for this symbol
  35. num = LETTERS.find(symbol) # get the number of the symbol
  36. if mode == 'encrypt':
  37. num = num + key
  38. elif mode == 'decrypt':
  39. num = num - key
  40.  
  41. # handle the wrap-around if num is larger than the length of
  42. # LETTERS or less than 0
  43. if num >= len(LETTERS):
  44. num = num - len(LETTERS)
  45. elif num < 0:
  46. num = num + len(LETTERS)
  47.  
  48. # add encrypted/decrypted number's symbol at the end of translated
  49. translated = translated + LETTERS[num]
  50.  
  51. else:
  52. # just add the symbol without encrypting/decrypting
  53. translated = translated + symbol
  54.  
  55. # print the encrypted/decrypted string to the screen
  56. print(translated)
  57.  
  58. # copy the encrypted/decrypted string to the clipboard
  59. pyperclip.copy(translated)
  60. x = 0
  61. while x<=3:
  62. wait = input("Enter anything to exit \n Enter \'n\' to wait \n")
  63. if wait == "n":
  64. print("Wating... \n")
  65. time.sleep(4)
  66. else:
  67. print ("Goodbye...")
  68. break
  69.  
  70. x=x+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement