270 http://inventwithpython.com/hacking
Email questions to the author: [email protected]
... letterMapping3 = simpleSubHacker.addLettersToMapping(letterMapping3,
'MPBKSSIPLC', candidates[i])
...
letterMapping3
{'A': [], 'C': ['Y', 'T'], 'B': ['M', 'S'], 'E': [], 'D': [], 'G': [], 'F': [],
'I': ['E', 'O'], 'H': [], 'K': ['I', 'A'], 'J': [], 'M': ['A', 'D'], 'L': ['L',
'N'], 'O': [], 'N': [], 'Q': [], 'P': ['D', 'I'], 'S': ['T', 'P'], 'R': [],
'U': [], 'T': [], 'W': [], 'V': [], 'Y': [], 'X': [], 'Z': []}
We intersect letterMapping3 with intersectedMapping. This also ends up indirectly
intersecting letterMapping3 with letterMapping1 and letterMapping2, since
intersectedMapping is currently the intersection of letterMapping1 and
letterMapping2. Try typing the following into the interactive shell:
intersectedMapping = simpleSubHacker.intersectMappings(intersectedMapping,
letterMapping3)
intersectedMapping
{'A': [], 'C': ['T'], 'B': ['S'], 'E': [], 'D': [], 'G': ['B'], 'F': [], 'I':
['O'], 'H': ['M'], 'K': ['A'], 'J': [], 'M': ['A', 'D'], 'L': ['N'], 'O':
['U'], 'N': ['L'], 'Q': ['C'], 'P': ['I'], 'S': ['T', 'P'], 'R': ['R'], 'U':
[], 'T': [], 'W': [], 'V': [], 'Y': [], 'X': ['F'], 'Z': ['E']}
We can now pass the intersected cipherletter mapping to
decryptWithCipherletterMapping() to decrypt the ciphertext. Try typing the
following into the interactive shell:
simpleSubHacker.decryptWithCipherletterMapping('OLQIHXIRCKGNZ PLQRZKBZB
MPBKSSIPLC', intersectedMapping)
UNCOMFORTABLE INCREASES _ISA__OINT
The intersected mapping is not yet complete. Notice how the intersected mapping has a solution
for the cipherletter K, because the key 'K'’s value to a list with just one string in it: ['A'].
Because we know that the K cipherletters will decrypt to A, no other cipherletter can possibly
decrypt to A.
In the intersected mapping, the cipherletter M maps to ['A', 'D']. This means that judging
from the candidates for the cipherwords in our encrypted message, the cipherletter M could
decrypt to A or D.