Skip to content

Instantly share code, notes, and snippets.

@ildus
Last active December 14, 2015 05:08
Show Gist options
  • Save ildus/5032837 to your computer and use it in GitHub Desktop.
Save ildus/5032837 to your computer and use it in GitHub Desktop.
#coding: utf-8
import enchant
LAT = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
a_list = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]
m = len(LAT)
CODE = """
NCPHIWDQ
"""
CODE_FULL = """
ZFA KAQG ZI VA SGAH CNA IVZCYPAH TNIW C KAQ GISNOA EFYOF GADAOZG ZFAW BANFCBG
NCPHIWDQ TNIW ZFA DCNMA GAZ IT CDD SGCVDA KAQG
"""
# 1 = a * aa % m
# 19 89 2, a a1 b
# THE KEYS TO BE USED ARE OBTAINED FROM A KEY SOURCE WHICH SELECTS THEM PERHAPS RANDOMLY FROM THE LARGE SET OF ALL USABLE KEYS
checker = enchant.Dict("en_US")
def decipher_whole(sentence, aa, b):
result = ''
for c in sentence:
if c in LAT:
code = LAT.index(c)
x = aa * (code - b) % m
result += LAT[x]
else:
result += ' '
print result
for a in a_list:
checked = False
aas = set([])
for aa in xrange(1, 100):
try:
assert a * aa % m == 1
aas.add(aa)
except:
continue
for aa in aas:
for b in xrange(1, 1000):
result = ''
for c in CODE:
if c in LAT:
code = LAT.index(c)
x = aa * (code - b) % m
result += LAT[x]
else:
result += ' '
result = result.replace(' ', '').lower()
if checker.check(result):
decipher_whole(CODE_FULL, aa, b)
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment