Created
June 5, 2015 07:58
-
-
Save lambda-fairy/1806a101b1ad34e1c80f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/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