From 9c734291b19b93d5d3233d0d565f66e6da111112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 19 Dec 2020 22:23:54 +0100 Subject: [PATCH] Updated: krzywa.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- 6/krzywa.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/6/krzywa.rb b/6/krzywa.rb index 22c10c1..127a662 100755 --- a/6/krzywa.rb +++ b/6/krzywa.rb @@ -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 + ##################################################