Hacking Secret Ciphers with Python

(Ann) #1

334 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


Attempting with key: ASIMOV
Possible encryption hack with key ASIMOV:
ALAN MATHISON TURING WAS A BRITISH MATHEMATICIAN, LOGICIAN, CRYPTANALYST, AND
COMPUTER SCIENTIST. HE WAS HIGHLY INFLUENTIAL IN THE DEVELOPMENT OF COMPUTER
SCIENCE, PROVIDING A FORMALISATION OF THE CON


Enter D for done, or just press Enter to continue hacking:



d
Copying hacked message to clipboard:
Alan Mathison Turing was a British mathematician, logician, cryptanalyst, and
computer scientist. He was highly influential in the development of computer



...skipped for brevity...


his death was accidental. On 10 September 2009, following an Internet campaign,
British Prime Minister Gordon Brown made an official public apology on behalf
of the British government for "the appalling way he was treated." As of May
2012 a private member's bill was before the House of Lords which would grant
Turing a statutory pardon if enacted.


How the Program Works..........................................................................................................................................


vigenereHacker.py



  1. Vigenere Cipher Hacker




  2. http://inventwithpython.com/hacking (BSD Licensed)





  3. import itertools, re

  4. import vigenereCipher, pyperclip, freqAnalysis, detectEnglish



  5. LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

  6. SILENT_MODE = False # if set to True, program doesn't print attempts

  7. NUM_MOST_FREQ_LETTERS = 4 # attempts this many letters per subkey

  8. MAX_KEY_LENGTH = 16 # will not attempt keys longer than this

  9. NONLETTERS_PATTERN = re.compile('[^A-Z]')


The hacking program imports many different modules, including a new module named
itertools. The constants will be explained as they are used in the program.


vigenereHacker.py
14. def main():
15. # Instead of typing this ciphertext out, you can copy & paste it
16. # from http://invpy.com/vigenereHacker.py
17. ciphertext = """Adiz Avtzqeci Tmzubb wsa m Pmilqev halpqavtakuoi,
lgouqdaf, kdmktsvmztsl, izr xoexghzr kkusitaaf. Vz wsa twbhdg ubalmmzhdad qz

Free download pdf