MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / findModInverse

Function findModInverse

ciphers/cryptomath_module.py:6–14  ·  view source on GitHub ↗
(a, m)

Source from the content-addressed store, hash-verified

4 return b
5
6def findModInverse(a, m):
7 if gcd(a, m) != 1:
8 return None
9 u1, u2, u3 = 1, 0, a
10 v1, v2, v3 = 0, 1, m
11 while v3 != 0:
12 q = u3 // v3
13 v1, v2, v3, u1, u2, u3 = (u1 - q * v1), (u2 - q * v2), (u3 - q *v3), v1, v2, v3
14 return u1 % m

Callers

nothing calls this directly

Calls 1

gcdFunction · 0.70

Tested by

no test coverage detected