Awesome-Python-Scripts/RSA-key-pairs/key-pair-generator.py
obiwan69 ab66a7a474 Create key-pair-generator.py
Create description.md

Create requirements.txt

Rename description.md to README.md

Update requirements.txt

Update README.md
2019-10-20 17:45:20 +05:30

21 lines
507 B
Python

#a simple RSA public key and private key pair generator
#using gcd from math module for coprimes
#and random for random numbers
import math
import random
p = random.randint(1,100)
q = random.randint(100,200)
if (math.gcd(p,q) == 1):
n = p * q
phi = (p-1)*(q-1)
k = 0
e = random.randint(1,20000)
if (math.gcd(phi,e)==1):
for i in range(1,20000):
d = (((phi * i) + 1)/e)
if d.is_integer():
k = d
break
print('Public key is: (',e,',',n,')')
print('Private key is: (',int(k),',',n,')')