From c66ce33e2efd3cebb172f0d4baedda8c6368c6e1 Mon Sep 17 00:00:00 2001
From: "dario.genga" <dario.genga@etu.hesge.ch>
Date: Sun, 29 May 2022 10:48:24 +0200
Subject: [PATCH] Add missing modulos

---
 main.py | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/main.py b/main.py
index bd6e542..067d180 100644
--- a/main.py
+++ b/main.py
@@ -179,7 +179,7 @@ def get_bezout_coefficients(a, b):
     y = [0, 1]
 
     while True:
-        r.append(r[i - 2] % r[i - 1])
+        r.append(modulo(r[i - 2], r[i - 1]))
 
         # Continue until the rest is equal to 0
         if r[i] == 0:
@@ -215,7 +215,7 @@ def modular_inverse(a, b):
         return None
 
     if bezout == 1 and modulo(a * x, b) == 1:
-        return format(x % b, STRING_BINARY_FORMAT)
+        return format(modulo(x, b), STRING_BINARY_FORMAT)
     return None
 
 
@@ -231,7 +231,7 @@ def inverse_add_mod(a):
     if type(a) == str:
         a = int(a, BINARY_BASE)
 
-    res = NIBBLE_BIT_SIZE - a
+    res = modulo(-a, NIBBLE_BIT_SIZE)
 
     return format(res, STRING_BINARY_FORMAT)
 
@@ -373,15 +373,14 @@ def encrypt(plaintext, subkeys):
             res_10 = add_mod(res_7, res_9)
             # 11. Bitwise XOR the results of steps 1 and 9
             res_11 = xor(res_1, res_9)
-            # 12. Bitwise XOR the results of steps 3 and 9
-            res_12 = xor(res_3, res_9)
-            # 13. Bitwise XOR the results of steps 2 and 10
-            res_13 = xor(res_2, res_10)
+            # 12. Bitwise XOR the results of steps 2 and 10
+            res_12 = xor(res_2, res_10)
+            # 13. Bitwise XOR the results of steps 3 and 9
+            res_13 = xor(res_3, res_9)
             # 14. Bitwise XOR the results of steps 4 and 10
             res_14 = xor(res_4, res_10)
             # Create the input for the next round with the final results
-            # The results of the steps 12 and 13 are swapped
-            input_block = res_11 + res_13 + res_12 + res_14
+            input_block = res_11 + res_12 + res_13 + res_14
 
         current_round += 1
 
-- 
GitLab