Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Caesar Cipher Decryption Script
Code to crack Google Security Key Challenge #3
Accompanying blog post:
@author: Jason Dsouza
from string import punctuation
ALPHABET = "abcdefghijklmnopqrstuvwxyz"
def create_caesar_cipher(N):
# we use the mod operator here to perform the wrap-around mentioned above
cipher = {ALPHABET[i]: ALPHABET[(i+N) % KEY_SPACE] for i, _ in enumerate(ALPHABET)}
return cipher
def decrypt(cipher, ciphertext):
# remember we need to ignore letter case and punctuation
decrypted = [letter if letter in punctuation + " " else cipher[letter] for letter in ciphertext.lower()]
return "".join(decrypted)
if __name__ == "__main__":
cipher_text = "Wuhdw brxu sdvvzrug olnh brxu wrrwkeuxvk. Grq'w ohw dqbergb hovh xvh lw, dqg jhw d qhz rqh hyhub vla prqwkv. Foliirug Vwroo"
for n in range(KEY_SPACE):
cipher = create_caesar_cipher(n)
plaintext = decrypt(cipher, cipher_text)
print("{}:\t{}".format(n, plaintext))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment