"""Caesar cipher solver""" # variables go here alphabet = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" letter_list = [] user_input = "" # functions here def encode(increment_repeat=0): """Encodes strings.""" for x in range(0, letter_amount): if (input_string[0 + increment_repeat]) == " ": increment_repeat += 1 letter_list.append(" ") elif (input_string[0 + increment_repeat]).isnumeric(): increment_repeat += 1 letter_list.append(input_string[-1 + increment_repeat]) else: letter = ord(input_string[0 + increment_repeat]) increment_repeat += 1 letter_list.append(alphabet[(letter - 97) + key]) def decode(increment_repeat=0): """Decodes strings.""" for x in range(0, letter_amount): if (input_string[0 + increment_repeat]) == " ": increment_repeat += 1 letter_list.append(" ") elif (input_string[0 + increment_repeat]).isnumeric(): increment_repeat += 1 letter_list.append(input_string[-1 + increment_repeat]) else: letter = ord(input_string[0 + increment_repeat]) increment_repeat += 1 letter_list.append(alphabet[(letter - 97) - key]) def crack(increment_repeat=0, crack_list=None): """Automatically prints every possible string.""" if crack_list is None: crack_list = [] for crack_phase in range(0, 26): for x in range(0, letter_amount): if (input_string[0 + increment_repeat]) == " ": increment_repeat += 1 crack_list.append(" ") elif (input_string[0 + increment_repeat]).isnumeric(): increment_repeat += 1 crack_list.append(input_string[-1 + increment_repeat]) else: letter = ord(input_string[0 + increment_repeat]) increment_repeat += 1 crack_list.append(alphabet[(letter - 97) + crack_phase]) crack_string = ''.join(crack_list) print(crack_string) crack_phase += 1 increment_repeat = 0 crack_list = [] print() print("Every possible string has been printed.") print("Check all of the strings and see if any of them reveal a message.") print("If not, then the original string was probably not encrypted using Caesar Cipher.") input_string = input("string? ") letter_amount = len(input_string) input_string.lower() while True: user_input = input("decode, encode or crack? ") if user_input == "decode" or user_input == "encode" or user_input == "crack": break else: print("Please choose an option") if user_input == "encode" or user_input == "decode": while True: key = int(input("key? ")) if 27 > key > -27: break else: print("key must be below 27 and above -27") while True: if user_input == "decode": decode() break elif user_input == "encode": encode() break elif user_input == "crack": crack() break printable_string = ''.join(letter_list) print(printable_string)