42 lines
1.0 KiB
Ruby
Executable File
42 lines
1.0 KiB
Ruby
Executable File
#!/usr/bin/ruby
|
|
# coding: utf-8
|
|
|
|
###################################
|
|
#
|
|
# Marcin Woźniak
|
|
# s434812
|
|
#
|
|
###################################
|
|
|
|
load '../module.rb'
|
|
|
|
def main
|
|
k = 300
|
|
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]
|
|
|
|
puts "Klucz pub: #{pubKey.inspect}"
|
|
puts "Klucz priv: #{privKey.inspect}"
|
|
puts ""
|
|
|
|
# BOB
|
|
c1, c2 = szyfrowanieElGamala(a,b,p,m,n,u,px,py,qx,qy)
|
|
|
|
# ALICE
|
|
pmd = deKododwanieElGamala(a,b,p,c1[0],c1[1],c2[0],c2[1],x)
|
|
d = algorytmDeSzyfrowania(pmd[0],pmd[1],u)
|
|
puts "Deszyfowany punkt #{pmd.inspect}"
|
|
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
|