Hacking Secret Ciphers with Python

(Ann) #1

188 http://inventwithpython.com/hacking


Email questions to the author: [email protected]



  1. def main():


  2. You might want to copy & paste this text from the source code at




  3. http://invpy.com/transpositionHacker.py



  4. myMessage = """Cb b rssti aieih rooaopbrtnsceee er es no npfgcwu plri
    ch nitaalr eiuengiteehb(e1 hilincegeoamn fubehgtarndcstudmd nM eu eacBoltaetee
    oinebcdkyremdteghn.aa2r81a condari fmps" tad l t oisn sit u1rnd stara nvhn fs
    edbh ee,n e necrg6 8nmisv l nc muiftegiitm tutmg cm shSs9fcie ebintcaets h a
    ihda cctrhe ele 1O7 aaoem waoaatdahretnhechaopnooeapece9etfncdbgsoeb uuteitgna.
    rteoh add e,D7c1Etnpneehtn beete" evecoal lsfmcrl iu1cifgo ai. sl1rchdnheev sh
    meBd ies e9t)nh,htcnoecplrrh ,ide hmtlme. pheaLem,toeinfgn t e9yce da' eN eMp a
    ffn Fc1o ge eohg dere.eec s nfap yox hla yon. lnrnsreaBoa t,e eitsw il ulpbdofg
    BRe bwlmprraio po droB wtinue r Pieno nc ayieeto'lulcih sfnc ownaSserbereiaSm



  • eaiah, nnrttgcC maciiritvledastinideI nn rms iehn tsigaBmuoetcetias rn"""





  1. hackedMessage = hackTransposition(myMessage)



  2. if hackedMessage == None:

  3. print('Failed to hack encryption.')

  4. else:

  5. print('Copying hacked message to clipboard:')

  6. print(hackedMessage)

  7. pyperclip.copy(hackedMessage)





  8. def hackTransposition(message):

  9. print('Hacking...')




  10. Python programs can be stopped at any time by pressing Ctrl-C (on




  11. Windows) or Ctrl-D (on Mac and Linux)



  12. print('(Press Ctrl-C or Ctrl-D to quit at any time.)')




  13. brute-force by looping through every possible key



  14. for key in range(1, len(message)):

  15. print('Trying key #%s...' % (key))



  16. decryptedText = transpositionDecrypt.decryptMessage(key, message)



  17. if detectEnglish.isEnglish(decryptedText):


  18. Check with user to see if the decrypted key has been found.



  19. print()

  20. print('Possible encryption hack:')

  21. print('Key %s: %s' % (key, decryptedText[:100]))

  22. print()

  23. print('Enter D for done, or just press Enter to continue
    hacking:')

  24. response = input('> ')

Free download pdf