Hacking Secret Ciphers with Python

(Ann) #1

386 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


8646830531744960702788478777031572995978999471326531132766377616771007701834003
6668306612665759417207845823479903440572724068125211002329298338718615859542093
72109725826359561748245019920074018549204468791300114315056117093,
4767673579813771041216688491698376504317312028941690434129597155228687099187466
6099933371008075948549008551224760695942666962465968168995404993934508399014283
0537106767608359489023128886399384026861870750523607730623641626642761449656525
5854533116668173598098138449334931305875025941768372702963348445191139635826000
8181223734862132564880771928931192572481077942568188460364002867327313529283117
0178614206817165802812291528319562200625082557261680470845607063596018339193179
7437503163601143217769616471700002543036826990539739057474642785416933878499897
014777481407371328053001838085314443545845219087249544663398589)


The public key is a 617 and a 309 digit number.
Writing public key to file al_sweigart_pubkey.txt...


The private key is a 617 and a 309 digit number.
Writing private key to file al_sweigart_privkey.txt...


These two keys are written out to two different files, al_sweigart_pubkey.txt and
al_sweigart_privkey.txt. These filenames are used because the string 'al_sweigart' was
passed to the makeKeyFiles() function. You can specify a different filenames by passing a
different string. These key files will be used by the RSA cipher program to encrypt and decrypt
messages.


If you try to run makeRsaKeys.py again with the same string being passed to
makeKeyFiles(), the output of the program will look like this:


Making key files...
WARNING: The file al_sweigart_pubkey.txt or al_sweigart_privkey.txt already
exists! Use a different name or delete these files and re-run this program.


This warning is here so you don’t accidentally overwrite your key files, making any files you
encrypted with them impossible to recover. Keep your keys safe!


How the Key Generation Program Works


makeRsaKeys.py



  1. RSA Key Generator




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





  3. import random, sys, os, rabinMiller, cryptomath


The program imports the rabinMiller and cryptomath modules that we created in the last
chapter, along with a few others.

Free download pdf