Updated: krzywa.rb

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-12-19 22:23:54 +01:00
parent 56ba08a7af
commit 9c734291b1
Signed by: y0rune
GPG Key ID: F204C385F57EB348

View File

@ -33,7 +33,7 @@ def generatorKrzywej(p)
b = 0
while true
if primalityTest(p) && p % 4 == 3
if primalityTest(p) && (p % 4 == 3)
threads = []
threads << Thread.new {
@ -45,11 +45,13 @@ def generatorKrzywej(p)
}
ThreadsWait.all_waits(*threads)
if delta(a,b,p) != 0
returnRownanie(a,b,p)
return a,b
end
else
puts "Liczba nie spełnia wymagań"
break
end
end
end
@ -82,6 +84,12 @@ def punktPrzeciwny(x,y)
end
def sumaPunktow(a,b,p,x1,y1,x2,y2)
# 0 - element neutrany --> P + 0 = P
if (x1 == "e" && y1 == "e" )
return x2,y2
elsif (x2 == "e" && y2 == "e")
return x1,y1
end
# P + Q = R
if (x1 != x2)
lambda = (((y2 - y1) % p) * reciprocal_Phi_p((x2 - x1),p)) % p
@ -92,7 +100,7 @@ def sumaPunktow(a,b,p,x1,y1,x2,y2)
# P + -Q = 0 DZIALA
if (x1 == x2) && (y1 == -y2)
puts "0 - el.neutralny"
return "0"
return e,e
end
# P + P = 2P DZIALA
if (x1 == x2) && (y1 == y2)
@ -101,12 +109,6 @@ def sumaPunktow(a,b,p,x1,y1,x2,y2)
y3 = (lambda * (x1 - x3) - y1) % p
return x3,y3
end
# 0 - element neutrany --> P + 0 = P
if (x1 == 0 && y1 == 0 )
return x2,y2
elsif (x2 == 0 && y2 == 0)
return x1,y1
end
end
#puts generatorKrzywej(11).inspect
@ -148,7 +150,7 @@ yr = 0
puts punktPrzeciwny(xq,yq).inspect
# 2) R + [0,0]
puts sumaPunktow(a,b,p,xr,yr,0,0).inspect
puts sumaPunktow(a,b,p,xr,yr,"e","e").inspect
# 3) P + Q
puts sumaPunktow(a,b,p,xp,yp,xq,yq).inspect
@ -195,4 +197,5 @@ qx=q[0].to_i
qy=q[1].to_i
r=sumaPunktow(a,b,p,px,py,qx,qy)
puts "P+Q=R=" + r.inspect
##################################################