44 lines
1.1 KiB
Ruby
Executable File
44 lines
1.1 KiB
Ruby
Executable File
#!/usr/bin/ruby
|
|
# coding: utf-8
|
|
|
|
###################################
|
|
#
|
|
# Marcin Woźniak
|
|
# s434812
|
|
#
|
|
###################################
|
|
|
|
load '../module.rb'
|
|
|
|
def main
|
|
k = 30
|
|
m = 73
|
|
n = m + SecureRandom.random_number(0..1000000)
|
|
u = SecureRandom.random_number(30..50)
|
|
a,b,p,px,py,qx,qy,x = generowanieKluczyElGamalKrzywaEliptyczna(k)
|
|
|
|
pubKey = [a,b,p,px,py,qx,qy]
|
|
privKey = [a,b,p,px,py,qx,qy,x]
|
|
|
|
pm = szyfrowanieElGamala(m,n,u,a,b,p,px,py,qx,qy)
|
|
|
|
# BOB
|
|
y = SecureRandom.random_number(0..liczenieOrd(a,b,p))
|
|
c1 = wielokrotnoscPunktu(a,b,p,y,px,py)
|
|
yq = wielokrotnoscPunktu(a,b,p,y,qx,qy)
|
|
c2 = sumaPunktow(a,b,p,pm[0],pm[1],yq[0],yq[1])
|
|
puts "Ciphers: #{c1} + #{c2}"
|
|
|
|
# ALICE
|
|
xc1 = wielokrotnoscPunktu(a,b,p,x,c1[0],c1[1])
|
|
pmd = sumaPunktow(a,b,p,c2[0],c2[1],xc1[0],-xc1[1])
|
|
d = algorytmDeKodowania(a,b,p,pmd[0],pmd[1],n,u)
|
|
puts "Dekodowana wiadomość #{d.inspect}"
|
|
end
|
|
|
|
#puts generowanieKluczyElGamalKrzywaEliptyczna(2048).inspect
|
|
#puts wielokrotnoscPunktu(8,10,19,3,15,3).inspect
|
|
#puts algorytmSzyfrowania(8,10,19,29102901920190,29102901920199,50).inspect
|
|
#puts algorytmDeSzyfrowania(8,10,19,12,17,50)
|
|
puts main.inspect
|