Created
April 5, 2013 11:07
-
-
Save joakibj/5318503 to your computer and use it in GitHub Desktop.
Here is a more general simple caesar decode solution, using brute force through lookup tables. Both upper and lower case.
Ukas nøtt #1
This file contains 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
import sys, string | |
def caesar_decode(x, substitution): | |
transtable = string.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', ''.join(substitution)) | |
return x.translate(transtable) | |
def rotateRight(substitution): | |
return (substitution[0][-1] + substitution[0][:-1], substitution[1][-1] + substitution[1][:-1]) | |
def main(): | |
cipher = 'Qh re xnafxwr zhyvtraf ra ivaare' | |
substitution = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz") | |
for i in range(1, 27): | |
substitution = rotateRight(substitution) | |
print 'r: %(rotation)02d - %(decoded_cipher)s ' % \ | |
{'rotation': i, 'decoded_cipher': caesar_decode(cipher, substitution)} | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment