320 http://inventwithpython.com/hacking
Email questions to the author: [email protected]
- def hackVigenere(ciphertext):
- fo = open('dictionary.txt')
- words = fo.readlines()
- fo.close()
- for word in words:
- word = word.strip() # remove the newline at the end
- decryptedText = vigenereCipher.decryptMessage(word, ciphertext)
- if detectEnglish.isEnglish(decryptedText, wordPercentage=40):
Check with user to see if the decrypted key has been found.
- print()
- print('Possible encryption break:')
- print('Key ' + str(word) + ': ' + decryptedText[:100])
- print()
- print('Enter D for done, or just press Enter to continue
breaking:') - response = input('> ')
- if response.upper().startswith('D'):
- return decryptedText
- if name == 'main':
- main()
Sample Run of the Vigenère Dictionary Hacker Program
When you run this program the output will look like this:
Possible encryption break:
Key ASTROLOGY: The recl yecrets crk not the qnks I tell.
Enter D for done, or just press Enter to continue breaking:
Possible encryption break:
Key ASTRONOMY: The real secrets are not the ones I tell.
Enter D for done, or just press Enter to continue breaking:
d
Copying hacked message to clipboard:
The real secrets are not the ones I tell.
The first keyword it suggests (“ASTROLOGY”) doesn’t quite work, so the user presses Enter to
let the hacking program continue until it gets the correct decryption key (“ASTRONOMY”).