Created
November 11, 2016 18:55
-
-
Save hughdbrown/736e35ae60b7331fd596345fd0de8d86 to your computer and use it in GitHub Desktop.
Produce candidates for solution of a Caesar cipher using a dictionary
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
from os.path import expanduser | |
def match_word(pattern, wordfile=None): | |
wordfile = wordfile or os.path.expanduser("~/Downloads/sowpods.txt") | |
with open(wordfile) as handle: | |
for line in handle: | |
word = line.rstrip().lower() | |
lookup = {c: d for c, d in zip(pattern, word)} | |
if "".join(lookup.get(c, '!') for c in pattern) == word: | |
yield word | |
pattern = "PIKODENHFENJIKM" | |
for word in match_word(pattern): | |
print(word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment