From 25edc1e9944ef1c4c70dba5a87b5bb9020d9b83f Mon Sep 17 00:00:00 2001
From: Jonas STIRNEMANN <jonas@stirnemann.xyz>
Date: Thu, 9 Dec 2021 11:13:21 +0100
Subject: [PATCH] Remade multiplicative inverse method

---
 inverse_mult.py | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/inverse_mult.py b/inverse_mult.py
index b4ca769..83d4034 100644
--- a/inverse_mult.py
+++ b/inverse_mult.py
@@ -1,9 +1,19 @@
 # Created : 06/12/2021
+# Refactored : 09/12/2021
 
-import math
+from euclide import *
 
+# Get the multiplicvative inverse of a Mod p
+# x = Multiplicative inverse of a mod p:
+# a * x mod p = 1
 def inverse_mult(a, p) :
-    c = abs(a^-1 % p)
-    if(p - c + abs(a) == 1):
-        return c
-    return False
+    pgcd, x, y =  pgcd_etendu(a, p)
+    if pgcd != 1:
+        return None
+    if a > p:
+        return x
+    else:
+        return y
+
+if __name__ == "__main__":
+    print(inverse_mult(3, 11))
\ No newline at end of file
-- 
GitLab