Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Created November 11, 2016 18:55
Show Gist options
  • Save hughdbrown/736e35ae60b7331fd596345fd0de8d86 to your computer and use it in GitHub Desktop.
Save hughdbrown/736e35ae60b7331fd596345fd0de8d86 to your computer and use it in GitHub Desktop.
Produce candidates for solution of a Caesar cipher using a dictionary
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