
CAESAR CIPHER TRANSLATOR CODE
Print "I love to review code at midnight because I have no life".translate(cipher) import stringĬipher = string.maketrans(ascii_lowercase, ascii_lowercase + ascii_lowercase) More, when building the translation table, in Python 2, we have string.maketrans. In Python, we have the translate method which applies a substitution cipher to a string. Here, you can read more about formatting. You should use format() when printing.In collectKey(): you can remove both continue statements.In collectMessage() you can directly return raw_input("Enter the message you would like to translate:\n\n").It's pretty weird to use exit which is a helper for the interactive shell instead of sys.exit which is intended for use in programs.you should add the if _name_ = '_main_' guard.Instead of commenting lines at the middle of the method, just add a docstring: def choose_mode(): function names should be snake_cased not camelCased.Some style notes (you can read more 'bout them on Python's official style-guide which is called PEP8):

Print "A Caeser Key of ", str(index), "reveals:\t", translateMessage(text, cipher_mode, 26 - index)īruteForce(entered_message, choice_of_mode)įinal_form = translateMessage(entered_message, choice_of_mode, entered_key) # Then Apply the Key then Modulate then Move Back Up then Build into Chr and Translation # Shift num down to 1 through 26 for more easier to visualize modulous. # If decrypting, convert key to negative.


Print("Please enter an integer between 0 and 26.\n")ĭef translateMessage(text, cipher_mode, caeser_key): Key = raw_input("What is the key for your message? (Enter a number from 0 to 26): \n") Message = raw_input("Enter the message you would like to translate:\n\n") Mode = raw_input("\nChoose a mode (encryption or decryption):\n 1) Encrypt \n 2) Decrypt\n 3) Brute Force\n\n") It works fine, but I'm curious if there are any constructive critiques, tips, tricks, comments, or advice anyone may have on how the code operates, performs, looks, etc. I wrote an encryption/decryption algorithm for the Caesar Cipher.
