Updated
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
45ae34eb5c
commit
25f32f3659
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/ruby
|
||||
# coding: utf-8
|
||||
|
||||
######################################
|
||||
#
|
||||
@ -7,9 +8,11 @@
|
||||
#
|
||||
#####################################
|
||||
|
||||
load 'modul1.rb'
|
||||
load '../module.rb'
|
||||
n=27558470307440807219575682445016430658685939156856477981777500279476244420599603476748648980604761766608173748421620897170615333674094203575560097701690600826765406153596728525522315006116823384679389665857084287734253844405374570906508352529980913768864581357633034050503316047153788822635367810607315822926036124094287753417643415534136727508769976105166846205170174541587788697208216080000563807101454012030501696997416883981774325045315898834544625445196823745452535408968088842047986215565636998321471356227742283630803792491817788329982895051126047698957867121151892976870203507010533578712963435
|
||||
b=21875839411860645751733414110507990938211947727566391650896268008014380471972884571819736247050909728035053094674608860293328893562160370394486537468106530827734742365411685767421588718185228782785552003001901855737170458066041248113076076995829550562900882883523060263336325733268287346885180980638925314361707330025700091411497796538991591403928171963244057349974038193893033645118506895181867417354461306709371353246617609796519071938239982148796049681802334559009898901024618676368438304178254967098179018064625240466547107577198806528894531245365445740726881296825273420342141309804295596060104598
|
||||
a = reciprocal_Phi_p(b,n)
|
||||
|
||||
puts a.inspect
|
||||
|
||||
|
||||
|
64
6/krzywa.rb
64
6/krzywa.rb
@ -55,17 +55,14 @@ def generatorKrzywej(p)
|
||||
end
|
||||
|
||||
def punktNaKrzywej(a,b,p)
|
||||
if delta(a,b,p) != 0
|
||||
if (delta(a,b,p) != 0) && (p % 4 == 3)
|
||||
while true
|
||||
x = SecureRandom.random_number(1..p-1)
|
||||
fx = rownanieKrzywej(a,b,p,x)
|
||||
if remSqEuler(fx,p)
|
||||
if p % 4 == 3
|
||||
#y = Math.sqrt(fx).to_i % p
|
||||
y = betterExponentiation(x,(p+1/4),p)
|
||||
end
|
||||
return x,y
|
||||
end
|
||||
x = SecureRandom.random_number(0..p-1)
|
||||
fx = rownanieKrzywej(a,b,p,x)
|
||||
if remSqEuler(fx,p)
|
||||
y = betterExponentiation(fx,((p+1)/4),p)
|
||||
return x,y
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -76,7 +73,6 @@ def czyPunktNalezyDoKrzywej(a,b,p,x,y)
|
||||
if fx == betterExponentiation(y,2,p)
|
||||
return true
|
||||
else
|
||||
puts rownanieKrzywej(a,b,p,x).inspect
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -88,9 +84,9 @@ end
|
||||
def sumaPunktow(a,b,p,x1,y1,x2,y2)
|
||||
# P + Q = R
|
||||
if (x1 != x2) && (y1 != y2)
|
||||
alpha = (((y2 - y1) % p) * reciprocal_Phi_p((x2 - x1),p)) % p
|
||||
x3 = (betterExponentiation(alpha,2,p) - (x1 % p) - (x2 % p)) % p
|
||||
y3 = (alpha * (x1 - x3) - y1) % p
|
||||
lambda = (((y2 - y1) % p) * reciprocal_Phi_p((x2 - x1),p)) % p
|
||||
x3 = (betterExponentiation(lambda,2,p) - (x1 % p) - (x2 % p)) % p
|
||||
y3 = (lambda * (x1 - x3) - y1) % p
|
||||
return x3,y3
|
||||
end
|
||||
# P + -Q = 0 DZIALA
|
||||
@ -100,9 +96,9 @@ def sumaPunktow(a,b,p,x1,y1,x2,y2)
|
||||
end
|
||||
# P + P = 2P DZIALA
|
||||
if (x1 == x2) && (y1 == y2)
|
||||
alpha = (((3 * betterExponentiation(x1,2,p) % p + a) % p) * reciprocal_Phi_p(2 * y1,p)) % p
|
||||
x3 = (betterExponentiation(alpha,2,p) - (x1 % p) - (x2 % p)) % p
|
||||
y3 = (alpha * (x1 - x3) - y1) % p
|
||||
lambda = (((3 * betterExponentiation(x1,2,p) % p + a) % p) * reciprocal_Phi_p(2 * y1,p)) % p
|
||||
x3 = (betterExponentiation(lambda,2,p) - (x1 % p) - (x2 % p)) % p
|
||||
y3 = (lambda * (x1 - x3) - y1) % p
|
||||
return x3,y3
|
||||
end
|
||||
# 0 - element neutrany --> P + 0 = P
|
||||
@ -116,7 +112,7 @@ end
|
||||
#puts generatorKrzywej(11).inspect
|
||||
#puts punktNaKrzywej(2,7,11).inspect
|
||||
#puts czyPunktNalezyDoKrzywej(2,7,11,7,1).inspect
|
||||
#puts czyPunktNalezyDoKrzywej(2,7,11,2,2).inspect
|
||||
#puts czyPunktNalezyDoKrzywej(2,7,11,10,10).inspect
|
||||
#puts punktPrzeciwny(2,2).inspect
|
||||
#puts sumaPunktow(2,2,17,5,1,5,1).inspect
|
||||
|
||||
@ -150,16 +146,16 @@ xr = 6
|
||||
yr = 0
|
||||
|
||||
# 1) -Q
|
||||
puts punktPrzeciwny(xq,yq).inspect
|
||||
#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,0,0).inspect
|
||||
|
||||
# 3) P + Q
|
||||
puts sumaPunktow(a,b,p,xp,yp,xq,yq).inspect
|
||||
#puts sumaPunktow(a,b,p,xp,yp,xq,yq).inspect
|
||||
|
||||
# 4) 2R
|
||||
puts sumaPunktow(a,b,p,xp,yp,xp,yp).inspect
|
||||
#puts sumaPunktow(a,b,p,xp,yp,xp,yp).inspect
|
||||
##################################################
|
||||
|
||||
#puts generatorKrzywej(1183779584357076950937981497685946292711107412152534481102525547387604378262522402526266939).inspect
|
||||
@ -170,7 +166,6 @@ puts sumaPunktow(a,b,p,xp,yp,xp,yp).inspect
|
||||
#puts sumaPunktow(2,2,17,5,1,5,1).inspect
|
||||
|
||||
|
||||
|
||||
# Zadanie od profersora
|
||||
a=239614427021073265587611886177902927263167863041565491257781227550405368115731464059190159
|
||||
b=447169285435982716467332439542997876345372330045685811964291613238129105735899852114277221
|
||||
@ -179,14 +174,14 @@ px=28511363427946540331999658174016933832945460866981430913799017481424365599277
|
||||
py=598700530906084162596261101440667782569915319623798143751082061599951188013331503150304328
|
||||
|
||||
# Zadanie 1
|
||||
puts
|
||||
puts "Zadanie 1"
|
||||
puts generatorKrzywej(p).inspect
|
||||
#puts
|
||||
#puts "Zadanie 1"
|
||||
#puts generatorKrzywej(p).inspect
|
||||
|
||||
# Zadanie 2
|
||||
puts
|
||||
puts "Zadanie 2"
|
||||
puts punktNaKrzywej(a,b,p).inspect
|
||||
#puts
|
||||
#puts "Zadanie 2"
|
||||
#puts punktNaKrzywej(a,b,p).inspect
|
||||
|
||||
# Zadanie 3
|
||||
puts
|
||||
@ -194,18 +189,17 @@ puts "Zadanie 3"
|
||||
puts czyPunktNalezyDoKrzywej(a,b,p,px,py).inspect
|
||||
|
||||
# Zadanie 4
|
||||
puts
|
||||
puts "Zadanie 4"
|
||||
puts punktPrzeciwny(px,py).inspect
|
||||
#puts
|
||||
#puts "Zadanie 4"#
|
||||
#puts punktPrzeciwny(px,py).inspect
|
||||
|
||||
# Zadanie 5
|
||||
puts
|
||||
puts "Zadanie 5"
|
||||
q=sumaPunktow(a,b,p,px,py,px,py).inspect
|
||||
q=sumaPunktow(a,b,p,px,py,px,py)
|
||||
puts "P+P=Q=" + q.inspect
|
||||
|
||||
qx=q[0].to_i
|
||||
qy=q[1].to_i
|
||||
|
||||
r=sumaPunktow(a,b,p,px,py,qx,qy).inspect
|
||||
r=sumaPunktow(a,b,p,px,py,qx,qy)
|
||||
puts "P+Q=R=" + r.inspect
|
||||
|
Loading…
Reference in New Issue
Block a user