Created
February 10, 2014 07:26
-
-
Save jameslyons/8911771 to your computer and use it in GitHub Desktop.
delastelle cipher in python
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
from itertools import product | |
key = "EPSDUCVWYM ZLKXNBTFGORIJHAQ" | |
IND2L = dict(zip(list(product((1,2,3),repeat=3)),key)) | |
L2IND = dict(zip(key,list(product((1,2,3),repeat=3)))) | |
ptext = 'DEFEND THE EAST WALL OF THE CASTLE' | |
ctext = "" | |
for c in ptext: | |
ctext += ''.join([str(i) for i in L2IND[c]]) | |
print ctext | |
ptext2 = "" | |
for i in range(0,len(ctext),3): | |
ind = tuple([int(ctext[i+k]) for k in [0,1,2]]) | |
ptext2 += IND2L[ind] | |
print ptext2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment