Skip to content
Snippets Groups Projects

Resolve "Remake Modular inverse"

Merged jonas.stirnema requested to merge 10-remake-modular-inverse into main
1 file
+ 15
5
Compare changes
  • Side-by-side
  • Inline
+ 15
5
# 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
Loading