Added
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
e597885b3a
commit
298981f205
@ -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
|
||||
end
|
||||
end
|
||||
def generateKeys
|
||||
while true
|
||||
p = generatePrime(4096)
|
||||
q = generatePrime(4096)
|
||||
|
||||
n = p * q
|
||||
phi = (p-1)*(q-1)
|
||||
n = p * q
|
||||
phi = (p-1)*(q-1)
|
||||
|
||||
while true
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
return [n,e,d]
|
||||
end
|
||||
|
||||
d = reciprocal_Phi_p(e,phi)
|
||||
keys = generateKeys
|
||||
n = keys[0]
|
||||
e = keys[1]
|
||||
d = keys[2]
|
||||
|
||||
pubKey = [n,e]
|
||||
privKey = [n,d]
|
||||
|
Loading…
Reference in New Issue
Block a user