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 puts sock.gets
# Generate public and priv key # Generate public and priv key
while true def generateKeys
p = generatePrime(100) while true
q = generatePrime(100) p = generatePrime(4096)
if primalityTest(p) && primalityTest(q) q = generatePrime(4096)
break
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 end
return [n,e,d]
end end
n = p * q keys = generateKeys
phi = (p-1)*(q-1) n = keys[0]
e = keys[1]
while true d = keys[2]
e = SecureRandom.random_number(0..phi)
if nwd(e,phi) == 1
break
end
end
d = reciprocal_Phi_p(e,phi)
pubKey = [n,e] pubKey = [n,e]
privKey = [n,d] privKey = [n,d]