Modular Inverse: Code

bghalmeida

New member
Joined
Oct 13, 2020
Messages
14
Using extended Euclid's algorithm for finding modular inverses with python.

I have to continue this code but I'm having a lot of trouble to do it, can someone help me?

The code:

def gcd(a, b):
assert a >= 0 and b >= 0 and a + b > 0

while a > 0 and b > 0:
if a >= b:
a = a % b
else:
b = b % a
return max(a, b)

def divide(a, b, n):
assert n > 1 and a > 0 and gcd(a, n) == 1
# return the number x s.t. x = b / a (mod n) and 0 <= x <= n-1.
 
Top