KRzA/6/krzywa.rb

95 lines
1.7 KiB
Ruby
Executable File

#!/usr/bin/ruby
# coding: utf-8
#######################################
#
# Marcin Woźniak
# s434812
#
########################################
load '../module.rb'
require 'thread'
require 'thwait'
def returnRownanie(a,b,p)
puts
puts "Równanie krzywej jest równe: " + "Y^2 = X^3+" + a.inspect + "X+" + b.inspect + " mod "+ p.inspect
puts
end
def delta(a,b,p)
d = ((4 * betterExponentiation(a,3,p) % p) + (27 * betterExponentiation(b,2,p) % p)) % p
return d
end
def rownanieKrzywej(a,b,p,x)
fx = (betterExponentiation(x,3,p) + (a * x) % p + b % p) % p
return fx
end
def generatorKrzywej(p)
a = 0
b = 0
while true
#p = generate(300)
if primalityTest(p)
threads = []
threads << Thread.new {
a = SecureRandom.random_number(1..p-1)
}
threads << Thread.new {
b = SecureRandom.random_number(1..p-1)
}
ThreadsWait.all_waits(*threads)
if delta(a,b,p) != 0
returnRownanie(a,b,p)
return a,b
end
end
end
end
def punktNaKrzywej(a,b,p)
if delta(a,b,p) != 0
while true
x = SecureRandom.random_number(1..p-1)
fx = rownanieKrzywej(a,b,p,x)
if remSqEuler(fx,p)
y = Math.sqrt(fx).to_i #betterExponentiation(x,((p+1)/4),p)
return x,y
end
end
end
end
def czyPunktNalezyDoKrzywej(a,b,p,x,y)
fx = rownanieKrzywej(a,b,p,x)
if fx == betterExponentiation(y,2,p)
return true
else
return false
end
end
def punktPrzeciwny(x,y)
return x,-y
end
def sumaPunktow(a,b,p,x1,y1,x2,y2)
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 punktPrzeciwny(2,2).inspect