Chapter 24 – Public Key Cryptography and the RSA Cipher 385
- fo.close()
- print()
- print('The private key is a %s and a %s digit number.' %
(len(str(publicKey[0])), len(str(publicKey[1])))) - print('Writing private key to file %s_privkey.txt...' % (name))
- fo = open('%s_privkey.txt' % (name), 'w')
- fo.write('%s,%s,%s' % (keySize, privateKey[0], privateKey[1]))
- fo.close()
If makeRsaKeys.py is run (instead of imported as a module) call
the main() function.
- if name == 'main':
- main()
Sample Run of the RSA Key Generation Program
When you run the makeRsaKeys.py program, the output will look something like this (of course,
the numbers for your keys will be different since they are random numbers):
Making key files...
Generating p prime...
Generating q prime...
Generating e that is relatively prime to (p-1)*(q-1)...
Calculating d that is mod inverse of e...
Public key:
(210902406316700502401968491406579417405090396754616926135810621216116191338086
5678407459875355468897928072386270510720443827324671435893274858393749685062411
6776147241821152026946322876869404394483922202407821672864242478920813182699000
8473526711744296548563866768454251404951960805224682425498975230488955908086491
8521163487778495362706850854469709529156400505222122042218037444940658810103314
8646830531744960702788478777031572995978999471326531132766377616771007701834003
6668306612665759417207845823479903440572724068125211002329298338718615859542093
72109725826359561748245019920074018549204468791300114315056117093,
1746023076917516102173184545923683355383240391086912905495420037367858093524760
6622265764388235752176654737805849023006544732896308685513669509917451195822611
3980989513066766009588891895645995814564600702703936932776834043548115756816059
906591453170741270845572335375041024799371425300216777273298110097435 989)
Private key:
(210902406316700502401968491406579417405090396754616926135810621216116191338086
5678407459875355468897928072386270510720443827324671435893274858393749685062411
6776147241821152026946322876869404394483922202407821672864242478920813182699000
8473526711744296548563866768454251404951960805224682425498975230488955908086491
8521163487778495362706850854469709529156400505222122042218037444940658810103314