From 7fd51c072d32effa0575f650b01a93dfb1069515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Thu, 21 Jan 2021 12:28:44 +0100 Subject: [PATCH] Module4 - has been ended 1,2,3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- module.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/module.rb b/module.rb index 9d88025..ffa2895 100755 --- a/module.rb +++ b/module.rb @@ -587,6 +587,7 @@ end ################################################################################# def xtime(a) binA = a.to_i(16).to_s(2) + const = "1B".to_i(16).to_s(2) dl = binA.length while dl != 8 binA = "0" + binA @@ -594,10 +595,8 @@ def xtime(a) end if binA[0].to_i == 1 binA[0] = '' - binA = binA + "0" - return (binA.to_i(2) ^ "1B".to_i(16).to_s(2).to_i(2)).to_s(16) + return ((binA.to_i(2) << 1) ^ const.to_i(2)).to_s(16) elsif binA[0].to_i == 0 - binA[0] = '' return (binA.to_i(2) << 1 ).to_s(16) end end @@ -607,7 +606,7 @@ end # Funkcja iloczyn(a,b) wykorzystujac liczby hex ################################################################################# def iloczyn(a,b) - solve = "" + solve = "0" binA = a.to_i(16).to_s(2) dl = binA.length @@ -618,17 +617,17 @@ def iloczyn(a,b) len = binA.length - 1 binA.split('').each { |a| - counter = len - 2 - tmp = xtime(b) - puts counter - while counter != 0 - tmp = xtime(tmp) - counter = counter - 1 + if a == "1" + tmp = b + counter = len + while counter != 0 + tmp = xtime(tmp) + counter = counter - 1 + end + solve = suma(tmp.to_i(16).to_s(16), solve) end - puts tmp - #puts solve - solve = suma((a.to_i * tmp.to_i(16)).to_s(16), solve) len = len - 1 } + return solve end