Added version 1

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-11-07 18:33:34 +01:00
commit 63e97d3f52
Signed by: y0rune
GPG Key ID: F204C385F57EB348
6 changed files with 122 additions and 0 deletions

Binary file not shown.

BIN
1/cw1_algkrypto1.pdf Normal file

Binary file not shown.

BIN
1/kryptoalg1.pdf Normal file

Binary file not shown.

BIN
2-lab/lab1.pdf Normal file

Binary file not shown.

BIN
2-lab/lab1_kryptoalgo.pdf Normal file

Binary file not shown.

122
2-lab/modul1.rb Executable file
View File

@ -0,0 +1,122 @@
#!/usr/bin/ruby
#####################################
#
# Marcin Woźniak
# s434812
#
# Last edit: 27-10-2020
#
#####################################
#!/usr/bin/ruby
require 'prime'
require 'openssl'
require 'securerandom'
require 'prime'
def extended_euklides(a, b)
return 1, 0 if b == 0
q, r = a.divmod b
s, t = extended_euklides(b, r)
return t, s - q * t
end
## Zad. 1.1
def random_gen_Zn(n,k)
#b = k.to_s(2).count "[0-1]"
#r = SecureRandom.random_number(n)
#x = r.to_s(2).count "[0-1]"
#until x != b do
# #if r < n then
# r = SecureRandom.random_number(n)
# x = r.to_s(2).count "[0-1]"
# puts r
# puts x
# #end
#end
#return r
if 2**(k-1) < n && k > 0 then
if k == 1 then
min = 0
max = 1
else
min = 2**(k-1)
max = (2**k)-1
end
end
r = rand(min..max)
while true do
ra = rand(min..max)
if ra < n then
break
end
end
return ra
end
## Zad. 1.2
def reciprocal_Phi_n(n,b)
u = extended_euklides(n,b)[0]
v = extended_euklides(n,b)[1]
if v % n == 0 then
return v
else
return u
end
end
## Zad. 1.3
def betterExponentiation(x,k,n)
b = x.to_s(2)
l = b.count "[0-1]"
y = 1
i = l - 1
for j in 1..i
y = y**2 % n
if b[-1*(j)]
y = y * x % n
end
end
return y
end
## Zad. 1.4
def remSqEuler(a,p)
ans = betterExponentiation(a,(p-1)/2,p)
if ans > 0 && Prime.prime?(p) then
return true
else
return false
end
end
## Zad. 1.5
def squareRootFp(a)
p = 3 % 4
if remSqEuler(a,p) then
bp = betterExponentiation(a,(p+1)/4,4) % 4
bm = -1 * bp
return bp,bm
end
end
#puts extended_euklides(10,13)
puts random_gen_Zn(50,3)
#puts reciprocal_Phi_n(10,13)
#puts betterExponentiation(112218876,2,10)
#puts remSqEuler(3,13)
#puts squareRootFp(13)