Updated
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
25f32f3659
commit
891a862eb8
49
6/krzywa.rb
49
6/krzywa.rb
@ -55,7 +55,7 @@ def generatorKrzywej(p)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def punktNaKrzywej(a,b,p)
|
def punktNaKrzywej(a,b,p)
|
||||||
if (delta(a,b,p) != 0) && (p % 4 == 3)
|
if (delta(a,b,p) != 0) && (p % 4 == 3)
|
||||||
while true
|
while true
|
||||||
x = SecureRandom.random_number(0..p-1)
|
x = SecureRandom.random_number(0..p-1)
|
||||||
fx = rownanieKrzywej(a,b,p,x)
|
fx = rownanieKrzywej(a,b,p,x)
|
||||||
@ -85,13 +85,13 @@ def sumaPunktow(a,b,p,x1,y1,x2,y2)
|
|||||||
# P + Q = R
|
# P + Q = R
|
||||||
if (x1 != x2) && (y1 != y2)
|
if (x1 != x2) && (y1 != y2)
|
||||||
lambda = (((y2 - y1) % p) * reciprocal_Phi_p((x2 - x1),p)) % p
|
lambda = (((y2 - y1) % p) * reciprocal_Phi_p((x2 - x1),p)) % p
|
||||||
x3 = (betterExponentiation(lambda,2,p) - (x1 % p) - (x2 % p)) % p
|
x3 = (betterExponentiation(lambda,2,p) - (x1 % p) - (x2 % p)) % p
|
||||||
y3 = (lambda * (x1 - x3) - y1) % p
|
y3 = (lambda * (x1 - x3) - y1) % p
|
||||||
return x3,y3
|
return x3,y3
|
||||||
end
|
end
|
||||||
# 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 "0"
|
||||||
end
|
end
|
||||||
# P + P = 2P DZIALA
|
# P + P = 2P DZIALA
|
||||||
@ -106,7 +106,7 @@ def sumaPunktow(a,b,p,x1,y1,x2,y2)
|
|||||||
return x2,y2
|
return x2,y2
|
||||||
elsif (x2 == 0 && y2 == 0)
|
elsif (x2 == 0 && y2 == 0)
|
||||||
return x1,y1
|
return x1,y1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#puts generatorKrzywej(11).inspect
|
#puts generatorKrzywej(11).inspect
|
||||||
@ -130,7 +130,6 @@ end
|
|||||||
# 3) P + Q
|
# 3) P + Q
|
||||||
# 4) 2R
|
# 4) 2R
|
||||||
#
|
#
|
||||||
##################################################
|
|
||||||
# Rozwiązanie:
|
# Rozwiązanie:
|
||||||
a = 0
|
a = 0
|
||||||
b = 1
|
b = 1
|
||||||
@ -146,27 +145,20 @@ xr = 6
|
|||||||
yr = 0
|
yr = 0
|
||||||
|
|
||||||
# 1) -Q
|
# 1) -Q
|
||||||
#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,0,0).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
|
||||||
|
|
||||||
# 4) 2R
|
# 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
|
##################################################
|
||||||
#puts punktNaKrzywej(239614427021073265587611886177902927263167863041565491257781227550405368115731464059190159,447169285435982716467332439542997876345372330045685811964291613238129105735899852114277221,1183779584357076950937981497685946292711107412152534481102525547387604378262522402526266939).inspect
|
# Zadanie od profersora
|
||||||
#puts czyPunktNalezyDoKrzywej(2,7,11,7,1).inspect
|
|
||||||
#puts czyPunktNalezyDoKrzywej(2,7,11,2,2).inspect
|
|
||||||
#puts punktPrzeciwny(2,2).inspect
|
|
||||||
#puts sumaPunktow(2,2,17,5,1,5,1).inspect
|
|
||||||
|
|
||||||
|
|
||||||
# Zadanie od profersora
|
|
||||||
a=239614427021073265587611886177902927263167863041565491257781227550405368115731464059190159
|
a=239614427021073265587611886177902927263167863041565491257781227550405368115731464059190159
|
||||||
b=447169285435982716467332439542997876345372330045685811964291613238129105735899852114277221
|
b=447169285435982716467332439542997876345372330045685811964291613238129105735899852114277221
|
||||||
p=1183779584357076950937981497685946292711107412152534481102525547387604378262522402526266939
|
p=1183779584357076950937981497685946292711107412152534481102525547387604378262522402526266939
|
||||||
@ -174,24 +166,24 @@ px=28511363427946540331999658174016933832945460866981430913799017481424365599277
|
|||||||
py=598700530906084162596261101440667782569915319623798143751082061599951188013331503150304328
|
py=598700530906084162596261101440667782569915319623798143751082061599951188013331503150304328
|
||||||
|
|
||||||
# Zadanie 1
|
# Zadanie 1
|
||||||
#puts
|
puts
|
||||||
#puts "Zadanie 1"
|
puts "Zadanie 1"
|
||||||
#puts generatorKrzywej(p).inspect
|
puts generatorKrzywej(p).inspect
|
||||||
|
|
||||||
# Zadanie 2
|
# Zadanie 2
|
||||||
#puts
|
puts
|
||||||
#puts "Zadanie 2"
|
puts "Zadanie 2"
|
||||||
#puts punktNaKrzywej(a,b,p).inspect
|
puts punktNaKrzywej(a,b,p).inspect
|
||||||
|
|
||||||
# Zadanie 3
|
# Zadanie 3
|
||||||
puts
|
puts
|
||||||
puts "Zadanie 3"
|
puts "Zadanie 3"
|
||||||
puts czyPunktNalezyDoKrzywej(a,b,p,px,py).inspect
|
puts czyPunktNalezyDoKrzywej(a,b,p,px,py).inspect
|
||||||
|
|
||||||
# Zadanie 4
|
# Zadanie 4
|
||||||
#puts
|
puts
|
||||||
#puts "Zadanie 4"#
|
puts "Zadanie 4"
|
||||||
#puts punktPrzeciwny(px,py).inspect
|
puts punktPrzeciwny(px,py).inspect
|
||||||
|
|
||||||
# Zadanie 5
|
# Zadanie 5
|
||||||
puts
|
puts
|
||||||
@ -203,3 +195,4 @@ 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