Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' cool Ceasar cypher encryptor/decryptor '''
- # made by Jeremy Carder Apr. 15, 2018
- try:
- import pyperclip
- except ModuleNotFoundError:
- pass
- import random
- mode = ''
- alphabet = "abcdefghijklmnopqrstuvwxyz"
- output = []
- def cryptor(encrypt):
- global output
- for letter in message:
- if letter == ".":
- output.append(".")
- elif letter == ",":
- output.append("")
- elif letter == " ":
- output.append(" ")
- else:
- if encrypt:
- comb = alphabet.index(letter) + int(shift)
- else:
- comb = alphabet.index(letter) - int(shift)
- if comb > 25:
- comb -= 26
- output.append(alphabet[comb])
- print(shift, "".join(output), "\n")
- if encrypt:
- try:
- pyperclip.copy("".join(output))
- print("(copied to clipboard)")
- except:
- print("Install the 'pyperclip' Python module to automatically copy encoded message to clipboard.")
- output = []
- print("Press 'q' to quit.")
- while mode != 'q':
- mode = input("\nEnter 'e' to encrypt or 'd' to decrypt: ")
- if mode != 'q':
- message = input("Message: ").lower()
- shift = input("Shift (random is default): ")
- if mode == 'e':
- if shift == "":
- shift = random.randint(0, 26)
- cryptor(True)
- else:
- if shift == "":
- for shift in range(0, 26):
- cryptor(False)
- else:
- cryptor(False)
Add Comment
Please, Sign In to add comment