Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-11-26 17:15:34 +01:00
parent e597885b3a
commit 298981f205
Signed by: y0rune
GPG Key ID: F204C385F57EB348

View File

@ -15,25 +15,30 @@ sock = TCPSocket.new("localhost",3000)
puts sock.gets
# Generate public and priv key
while true
p = generatePrime(100)
q = generatePrime(100)
if primalityTest(p) && primalityTest(q)
break
def generateKeys
while true
p = generatePrime(4096)
q = generatePrime(4096)
n = p * q
phi = (p-1)*(q-1)
e = SecureRandom.random_number(0..phi)
d = reciprocal_Phi_p(e,phi)
if primalityTest(p) && primalityTest(q) && nwd(e,phi) == 1 && d > 1
break
end
end
return [n,e,d]
end
n = p * q
phi = (p-1)*(q-1)
while true
e = SecureRandom.random_number(0..phi)
if nwd(e,phi) == 1
break
end
end
d = reciprocal_Phi_p(e,phi)
keys = generateKeys
n = keys[0]
e = keys[1]
d = keys[2]
pubKey = [n,e]
privKey = [n,d]