Module4 - has been ended 1,2,3

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-21 12:28:44 +01:00
parent 5f821e510f
commit 7fd51c072d
Signed by: y0rune
GPG Key ID: F204C385F57EB348
1 changed files with 12 additions and 13 deletions

View File

@ -587,6 +587,7 @@ end
################################################################################# #################################################################################
def xtime(a) def xtime(a)
binA = a.to_i(16).to_s(2) binA = a.to_i(16).to_s(2)
const = "1B".to_i(16).to_s(2)
dl = binA.length dl = binA.length
while dl != 8 while dl != 8
binA = "0" + binA binA = "0" + binA
@ -594,10 +595,8 @@ def xtime(a)
end end
if binA[0].to_i == 1 if binA[0].to_i == 1
binA[0] = '' binA[0] = ''
binA = binA + "0" return ((binA.to_i(2) << 1) ^ const.to_i(2)).to_s(16)
return (binA.to_i(2) ^ "1B".to_i(16).to_s(2).to_i(2)).to_s(16)
elsif binA[0].to_i == 0 elsif binA[0].to_i == 0
binA[0] = ''
return (binA.to_i(2) << 1 ).to_s(16) return (binA.to_i(2) << 1 ).to_s(16)
end end
end end
@ -607,7 +606,7 @@ end
# Funkcja iloczyn(a,b) wykorzystujac liczby hex # Funkcja iloczyn(a,b) wykorzystujac liczby hex
################################################################################# #################################################################################
def iloczyn(a,b) def iloczyn(a,b)
solve = "" solve = "0"
binA = a.to_i(16).to_s(2) binA = a.to_i(16).to_s(2)
dl = binA.length dl = binA.length
@ -618,17 +617,17 @@ def iloczyn(a,b)
len = binA.length - 1 len = binA.length - 1
binA.split('').each { |a| binA.split('').each { |a|
counter = len - 2 if a == "1"
tmp = xtime(b) tmp = b
puts counter counter = len
while counter != 0 while counter != 0
tmp = xtime(tmp) tmp = xtime(tmp)
counter = counter - 1 counter = counter - 1
end
solve = suma(tmp.to_i(16).to_s(16), solve)
end end
puts tmp
#puts solve
solve = suma((a.to_i * tmp.to_i(16)).to_s(16), solve)
len = len - 1 len = len - 1
} }
return solve return solve
end end