2020-12-12 01:16:55 +01:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
###################################
|
|
|
|
#
|
|
|
|
# Marcin Woźniak
|
|
|
|
# s434812
|
|
|
|
#
|
|
|
|
###################################
|
|
|
|
|
|
|
|
load '../module.rb'
|
2020-12-19 22:24:14 +01:00
|
|
|
|
|
|
|
def main
|
2021-01-05 17:25:55 +01:00
|
|
|
k = 400
|
|
|
|
m = 7382908210982109821098
|
2020-12-19 22:24:14 +01:00
|
|
|
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]
|
|
|
|
|
2020-12-30 21:09:43 +01:00
|
|
|
puts "Klucz pub: #{pubKey.inspect}"
|
|
|
|
puts "Klucz priv: #{privKey.inspect}"
|
|
|
|
puts ""
|
|
|
|
|
2020-12-19 22:24:14 +01:00
|
|
|
# BOB
|
2021-01-05 17:25:55 +01:00
|
|
|
pm = algorytmKodowania(a,b,p,m,u)
|
|
|
|
c1, c2 = szyfrowanieElGamala(a,b,p,u,px,py,qx,qy,pm[0],pm[1])
|
2020-12-19 22:24:14 +01:00
|
|
|
|
|
|
|
# ALICE
|
2021-01-02 17:34:59 +01:00
|
|
|
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}"
|
2020-12-19 22:24:14 +01:00
|
|
|
puts "Dekodowana wiadomość #{d.inspect}"
|
2021-01-05 17:25:55 +01:00
|
|
|
puts "\n\n---------------DANE DO ZADANIA----------------\nm = #{m} \na = #{a}\nb = #{b}\np = #{p}\npx = #{px}\npy = #{py}\nqx = #{qx}\nqy = #{qy}\nx = #{x}\nu = #{u}\nc1 = #{c1.inspect}\nc2 = #{c2.inspect}\n---------------------------------------------"
|
2020-12-19 22:24:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
#puts generowanieKluczyElGamalKrzywaEliptyczna(2048).inspect
|
|
|
|
#puts wielokrotnoscPunktu(8,10,19,3,15,3).inspect
|
|
|
|
#puts algorytmSzyfrowania(8,10,19,29102901920190,29102901920199,50).inspect
|
2021-01-05 17:25:55 +01:00
|
|
|
#Puts algorytmDeSzyfrowania(8,10,19,12,17,50)
|
|
|
|
|
|
|
|
def prof
|
|
|
|
p = 2609851093885672531604546618282965491657570314241630591985918197877686507680174634344306143
|
|
|
|
a = 39746926425836399039258105470873774392122997653409098298906197201548801192257224379572749
|
|
|
|
b = 357758004741884143788834147448966908166771657009672776346195608808675430720026748380346214
|
|
|
|
px = 1752779174606701535340714968386694890708439813322474322723061659600059923305207235005963526
|
|
|
|
py = 692575814560566162056537964537393338270737177090733420494053855669625561475768305447331017
|
|
|
|
qx = 1859733423522807921537556587280278373018778723945077866335841026984756695533872750973383203
|
|
|
|
qy = 2221415723705529494603362237538702810871518537067269952747134368932432130149327465664405538
|
|
|
|
pmx = 1632858042793817840589568786779891550617922233361846684642975374690944475963011731075819538
|
|
|
|
pmy = 1425948989523949818696633854257999800509690944329987427951625560436648299955576658406402833
|
|
|
|
u = 30
|
|
|
|
x = 365201008216944469945066035191785204730196821748386113747483955067753230980
|
|
|
|
|
|
|
|
y = SecureRandom.random_number(0..liczenieOrd(p))
|
|
|
|
|
|
|
|
c1 = wielokrotnoscPunktu(a,b,p,y,px,py)
|
|
|
|
puts "c1 #{c1}"
|
|
|
|
|
|
|
|
yq = wielokrotnoscPunktu(a,b,p,y,qx,qy)
|
|
|
|
c2 = sumaPunktow(a,b,p,pmx,pmy,yq[0],yq[1])
|
|
|
|
puts "c2 #{c2}"
|
|
|
|
|
|
|
|
pmd = deKododwanieElGamala(a,b,p,c1[0],c1[1],c2[0],c2[1],x)
|
|
|
|
d = algorytmDeSzyfrowania(pmd[0],pmd[1],u)
|
|
|
|
|
|
|
|
puts "pmd #{pmd.inspect}"
|
|
|
|
puts "d = #{d}"
|
|
|
|
end
|
|
|
|
|
|
|
|
#puts prof
|
2020-12-19 22:24:14 +01:00
|
|
|
puts main.inspect
|