Skip to content

Instantly share code, notes, and snippets.

@jameslyons
Created February 10, 2014 07:26
Show Gist options
  • Save jameslyons/8911771 to your computer and use it in GitHub Desktop.
Save jameslyons/8911771 to your computer and use it in GitHub Desktop.
delastelle cipher in python
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