Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Creative category for ADFGVX Cipher by Sim0000
M='ADFGVX'
def g(k,m):
k=sorted(set(k),key=k.index)
yield from[j for i in sorted(range(len(k)),key=k.__getitem__)for j in range(i,len(m),len(k))]
def encode(m,s,k):
x=[M[i]for c in m.lower()if c.isalpha()or c.isdigit()for i in divmod(s.index(c),6)]
return ''.join(x[i]for i in g(k,x))
def decode(m,s,k):
x=list(m)
for i,c in zip(g(k,m),m):x[i]=c
return ''.join(s[6*M.index(x[i])+M.index(x[i+1])]for i in range(0,len(m),2))
if __name__ == '__main__':
assert encode("I am going",
"dhxmu4p3j6aoibzv9w1n70qkfslyc8tr5e2g",
"cipher") == 'FXGAFVXXAXDDDXGA', "encode I am going"
assert decode("FXGAFVXXAXDDDXGA",
"dhxmu4p3j6aoibzv9w1n70qkfslyc8tr5e2g",
"cipher") == 'iamgoing', "decode I am going"
assert encode("attack at 12:00 am",
"na1c3h8tb2ome5wrpd4f6g7i9j0kjqsuvxyz",
"privacy") == 'DGDDDAGDDGAFADDFDADVDVFAADVX', "encode attack"
assert decode("DGDDDAGDDGAFADDFDADVDVFAADVX",
"na1c3h8tb2ome5wrpd4f6g7i9j0kjqsuvxyz",
"privacy") == 'attackat1200am', "decode attack"
assert encode("ditiszeergeheim",
"na1c3h8tb2ome5wrpd4f6g7i9j0kjqsuvxyz",
"piloten") == 'DFGGXXAAXGAFXGAFXXXGFFXFADDXGA', "encode ditiszeergeheim"
assert decode("DFGGXXAAXGAFXGAFXXXGFFXFADDXGA",
"na1c3h8tb2ome5wrpd4f6g7i9j0kjqsuvxyz",
"piloten") == 'ditiszeergeheim', "decode ditiszeergeheim"
assert encode("I am going",
"dhxmu4p3j6aoibzv9w1n70qkfslyc8tr5e2g",
"weasel") == 'DXGAXAAXXVDDFGFX', "encode weasel == weasl"
assert decode("DXGAXAAXXVDDFGFX",
"dhxmu4p3j6aoibzv9w1n70qkfslyc8tr5e2g",
"weasel") == 'iamgoing', "decode weasel == weasl"
Sept. 18, 2014
Comments: