Skip to content
Snippets Groups Projects
Commit 25edc1e9 authored by Jonas STIRNEMANN's avatar Jonas STIRNEMANN
Browse files

Remade multiplicative inverse method

parent e275fa49
Branches
No related tags found
1 merge request!9Resolve "Remake Modular inverse"
# Created : 06/12/2021 # 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) : def inverse_mult(a, p) :
c = abs(a^-1 % p) pgcd, x, y = pgcd_etendu(a, p)
if(p - c + abs(a) == 1): if pgcd != 1:
return c return None
return False if a > p:
return x
else:
return y
if __name__ == "__main__":
print(inverse_mult(3, 11))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment