268 http://inventwithpython.com/hacking
Email questions to the author: [email protected]
But since the letters in OLQIHXIRCKGNZ could also possibly decrypt to UNCOMFORTABLY,
we also need to add UNCOMFORTABLY to the cipherletter mapping. Try typing the following
into the interactive shell:
letterMapping1 = simpleSubHacker.addLettersToMapping(letterMapping1,
'OLQIHXIRCKGNZ', candidates[1])
letterMapping1
{'A': [], 'C': ['T'], 'B': [], 'E': [], 'D': [], 'G': ['B'], 'F': [], 'I':
['O'], 'H': ['M'], 'K': ['A'], 'J': [], 'M': [], 'L': ['N'], 'O': ['U'], 'N':
['L'], 'Q': ['C'], 'P': [], 'S': [], 'R': ['R'], 'U': [], 'T': [], 'W': [],
'V': [], 'Y': [], 'X': ['F'], 'Z': ['E', 'Y']}
You’ll notice that not much has changed in letterMapping1. The cipherletter mapping in
letterMapping1 now has 'Z' map to both 'E' and 'Y'. That’s because the candidates for
OLQIHXIRCKGNZ (that is, UNCOMFORTABLE and UNCOMFORTABLY) are very similar
to each other and addLettersToMapping() only adds the letter to the list if the letter is not
already there. This is why 'O' maps to ['U'] instead of ['U', 'U'].
We now have a cipherletter mapping for the first of the three cipherwords. We need to get a new
mapping for the second cipherword, PLQRZKBZB. Call
getBlankCipherletterMapping() and store the returned dictionary value in a variable
named letterMapping2. Get the word pattern for PLQRZKBZB and use it to look up all the
candidates in wordPatterns.allPatterns. This is done by typing the following into the
interactive shell:
letterMapping2 = simpleSubHacker.getBlankCipherletterMapping()
wordPat = makeWordPatterns.getWordPattern('PLQRZKBZB')
candidates = wordPatterns.allPatterns[wordPat]
candidates
['CONVERSES', 'INCREASES', 'PORTENDED', 'UNIVERSES']
Instead of typing out four calls to addLettersToMapping() for each of these four candidate
words, we can write a for loop that will go through the list in candidates and call
addLettersToMapping() each time.
for candidate in candidates:
... letterMapping2 = simpleSubHacker.addLettersToMapping(letterMapping2,
'PLQRZKBZB', candidate)
...
letterMapping2