diff --git a/inverse_mult.py b/inverse_mult.py index b4ca7699155f69598b74cbbc78d1cd73ca72bd4d..83d40345c6d7cb3115e50882d1263c4bf059600a 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