mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-27 14:01:09 +00:00
ab66a7a474
Create description.md Create requirements.txt Rename description.md to README.md Update requirements.txt Update README.md
21 lines
507 B
Python
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,')')
|