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