Skip to content

Instantly share code, notes, and snippets.

@drvinceknight
Last active August 29, 2015 14:16
Show Gist options
  • Save drvinceknight/b2548c24ad6487547b3d to your computer and use it in GitHub Desktop.
Save drvinceknight/b2548c24ad6487547b3d to your computer and use it in GitHub Desktop.
"""
A quick ceaser cipher; used to decrypt a message from a mysterious twitter account: https://twitter.com/cryptogram_app
"""
import string
alphabet = string.ascii_lowercase
def decrypt(encryption, key):
"""
Decrypt a ceaser cypher encrypted message
"""
plain_text = ''
encryption = encryption.lower()
for c in encryption:
if c== ' ':
plain_text += c
else:
plain_text += alphabet[(alphabet.index(c) + key) % 26]
return plain_text
for k in range(26):
print k, decrypt('Sdzl Hmehmhsx', k)
def encrypt(plain_text, key):
"""
Encrypts a plain text message using a ceaser cyper
"""
return decrypt(plain_text, -key)
print encrypt('I think I know', 1)
print decrypt(encrypt('I think I know', 1), 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment