# Caesar Cipher Hacker message = 'GUVF VF ZL FRPERG ZRFFNTR.' LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # loop through every possible key for key in range(len(LETTERS)): # It is important to set translated to the blank string so that the # previous iteration's value for translated is cleared. translated = '' # The rest of the program is the same as the original Caesar program: # run the encryption/decryption code on each symbol in the message for symbol in message: if symbol in LETTERS: num = LETTERS.find(symbol) # get the number of the symbol num = num - key # handle the wrap-around if num is 26 or larger or less than 0 if num < 0: num = num + len(LETTERS) # add number's symbol at the end of translated translated = translated + LETTERS[num] else: # just add the symbol without encrypting/decrypting translated = translated + symbol # display the current key being tested, along with its decryption print('Key #%s: %s' % (key, translated))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question