Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Created June 5, 2015 07:58
Show Gist options
  • Select an option

  • Save lambda-fairy/1806a101b1ad34e1c80f to your computer and use it in GitHub Desktop.

Select an option

Save lambda-fairy/1806a101b1ad34e1c80f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from collections import defaultdict
from functools import lru_cache
import string
cipher = ["BUGVIOVBGB", "QVAZHBGOLO", "UMCKVQHLBQ", "XBQMVGDXGU", "TDDDOUJWCZ",
"TIWQKKGXTX", "QQCCQKULXU", "CVVOQQZGZD", "UVGCGITVTQ", "VRHGOBBVKK"]
def load_words():
for line in open('/usr/share/dict/words'):
word = line.strip().lower()
if len(word) != 10: continue
if not all('a' <= c <= 'z' for c in word): continue
yield word
def normalize(word):
pool = iter(string.ascii_uppercase)
translate = lru_cache(maxsize=None)(lambda _: next(pool))
return ''.join(map(translate, word))
def main():
mapping = defaultdict(set)
for word in load_words():
key = normalize(word)
mapping[key].add(word)
for word in cipher:
print('{}: {}'.format(word, ', '.join(mapping[normalize(word)])))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment