Last active
August 29, 2015 14:16
-
-
Save drvinceknight/b2548c24ad6487547b3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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