Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Caesar Cipher
- # https://inventwithpython.com/hacking (BSD Licensed)
- import pyperclip
- import time
- # every possible symbol that can be encrypted
- LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+ '
- # tells the program to encrypt or decrypt
- mode = input("\033[0;32m Enter the mode type : \n 01 : Encrypt \n 02 : Decrypt \n") # set to 'encrypt' or 'decrypt'
- if mode == "01":
- mode="encrypt"
- if mode == "02":
- mode="decrypt"
- # The string to be encrypted/decrypted:
- message = input("Enter the secret message : \n")
- # the encryption/decryption key
- key = int( input("Enter the key: - \033[0;31m you can't decrypt without the key! \033[0;32m - \n") )
- # stores the encrypted/decrypted form of the message
- translated = ''
- # capitalize the string in message
- message = message.upper()
- # run the encryption/decryption code on each symbol in the message string
- for symbol in message:
- if symbol in LETTERS:
- # get the encrypted (or decrypted) number for this symbol
- num = LETTERS.find(symbol) # get the number of the symbol
- if mode == 'encrypt':
- num = num + key
- elif mode == 'decrypt':
- num = num - key
- # handle the wrap-around if num is larger than the length of
- # LETTERS or less than 0
- if num >= len(LETTERS):
- num = num - len(LETTERS)
- elif num < 0:
- num = num + len(LETTERS)
- # add encrypted/decrypted number's symbol at the end of translated
- translated = translated + LETTERS[num]
- else:
- # just add the symbol without encrypting/decrypting
- translated = translated + symbol
- # print the encrypted/decrypted string to the screen
- print(translated)
- # copy the encrypted/decrypted string to the clipboard
- pyperclip.copy(translated)
- x = 0
- while x<=3:
- wait = input("Enter anything to exit \n Enter \'n\' to wait \n")
- if wait == "n":
- print("Wating... \n")
- time.sleep(4)
- else:
- print ("Goodbye...")
- break
- x=x+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement