Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (25 sloc) 1.15 KB
# Caesar Cipher Breaker
# (BSD Licensed)
# 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 of less than 0
if num < 0:
num = num + len(LETTERS)
# add number's symbol at the end of translated
translated = translated + LETTERS[num]
# 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))
Jump to Line
Something went wrong with that request. Please try again.