Updated: krzywa.rb
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
56ba08a7af
commit
9c734291b1
23
6/krzywa.rb
23
6/krzywa.rb
@ -33,7 +33,7 @@ def generatorKrzywej(p)
|
|||||||
b = 0
|
b = 0
|
||||||
|
|
||||||
while true
|
while true
|
||||||
if primalityTest(p) && p % 4 == 3
|
if primalityTest(p) && (p % 4 == 3)
|
||||||
threads = []
|
threads = []
|
||||||
|
|
||||||
threads << Thread.new {
|
threads << Thread.new {
|
||||||
@ -45,11 +45,13 @@ def generatorKrzywej(p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThreadsWait.all_waits(*threads)
|
ThreadsWait.all_waits(*threads)
|
||||||
|
|
||||||
if delta(a,b,p) != 0
|
if delta(a,b,p) != 0
|
||||||
returnRownanie(a,b,p)
|
returnRownanie(a,b,p)
|
||||||
return a,b
|
return a,b
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
puts "Liczba nie spełnia wymagań"
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -82,6 +84,12 @@ def punktPrzeciwny(x,y)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def sumaPunktow(a,b,p,x1,y1,x2,y2)
|
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
|
# P + Q = R
|
||||||
if (x1 != x2)
|
if (x1 != x2)
|
||||||
lambda = (((y2 - y1) % p) * reciprocal_Phi_p((x2 - x1),p)) % p
|
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
|
# P + -Q = 0 DZIALA
|
||||||
if (x1 == x2) && (y1 == -y2)
|
if (x1 == x2) && (y1 == -y2)
|
||||||
puts "0 - el.neutralny"
|
puts "0 - el.neutralny"
|
||||||
return "0"
|
return e,e
|
||||||
end
|
end
|
||||||
# P + P = 2P DZIALA
|
# P + P = 2P DZIALA
|
||||||
if (x1 == x2) && (y1 == y2)
|
if (x1 == x2) && (y1 == y2)
|
||||||
@ -101,12 +109,6 @@ def sumaPunktow(a,b,p,x1,y1,x2,y2)
|
|||||||
y3 = (lambda * (x1 - x3) - y1) % p
|
y3 = (lambda * (x1 - x3) - y1) % p
|
||||||
return x3,y3
|
return x3,y3
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
#puts generatorKrzywej(11).inspect
|
#puts generatorKrzywej(11).inspect
|
||||||
@ -148,7 +150,7 @@ yr = 0
|
|||||||
puts punktPrzeciwny(xq,yq).inspect
|
puts punktPrzeciwny(xq,yq).inspect
|
||||||
|
|
||||||
# 2) R + [0,0]
|
# 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
|
# 3) P + Q
|
||||||
puts sumaPunktow(a,b,p,xp,yp,xq,yq).inspect
|
puts sumaPunktow(a,b,p,xp,yp,xq,yq).inspect
|
||||||
@ -195,4 +197,5 @@ qx=q[0].to_i
|
|||||||
qy=q[1].to_i
|
qy=q[1].to_i
|
||||||
r=sumaPunktow(a,b,p,px,py,qx,qy)
|
r=sumaPunktow(a,b,p,px,py,qx,qy)
|
||||||
puts "P+Q=R=" + r.inspect
|
puts "P+Q=R=" + r.inspect
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
|
Loading…
Reference in New Issue
Block a user