Skip to content

Instantly share code, notes, and snippets.

@joakibj
Created April 5, 2013 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joakibj/5318503 to your computer and use it in GitHub Desktop.
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
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