Added module2
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
17237eab0a
commit
c377c2d82e
92
6/krzywa.rb
Normal file → Executable file
92
6/krzywa.rb
Normal file → Executable file
@ -1,10 +1,94 @@
|
|||||||
#########################################
|
|
||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
#######################################
|
||||||
#
|
#
|
||||||
#
|
# Marcin Woźniak
|
||||||
#
|
# s434812
|
||||||
#
|
|
||||||
#
|
#
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
load '../module.rb'
|
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
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
#
|
#
|
||||||
@ -13,7 +14,7 @@ require 'prime'
|
|||||||
require 'thread'
|
require 'thread'
|
||||||
|
|
||||||
def nwd(a, b)
|
def nwd(a, b)
|
||||||
if a == 0
|
if a == 0
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
b == 0 ? a : nwd(b, a.modulo(b))
|
b == 0 ? a : nwd(b, a.modulo(b))
|
||||||
@ -120,7 +121,7 @@ def primalityTest(n)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
counter = 20
|
counter = 10
|
||||||
while (counter != 0) do
|
while (counter != 0) do
|
||||||
b = SecureRandom.random_number(2..n-2) # Tez dziala n-1
|
b = SecureRandom.random_number(2..n-2) # Tez dziala n-1
|
||||||
if betterExponentiation(b,n-1,n) != 1
|
if betterExponentiation(b,n-1,n) != 1
|
||||||
@ -168,4 +169,4 @@ end
|
|||||||
|
|
||||||
def generate(n)
|
def generate(n)
|
||||||
return `openssl prime -generate -bits '#{n}'`.gsub(/\n$/, '').to_i
|
return `openssl prime -generate -bits '#{n}'`.gsub(/\n$/, '').to_i
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user