Advertisement
UF6

Mod Inverse Finder

UF6
Jul 5th, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. def findModInverse(a, m):
  2.     if gcd(a, m) != 1:
  3.         return (None)
  4.     u1, u2, u3 = 1, 0, a
  5.     v1, v2, v3 = 0, 1, m
  6.     while v3 != 0:
  7.         q = u3 // v3
  8.         v1, v2, v3, u1, u2, u3 = (u1 - q * v1), (u2 - q * v2), (u3 - q * v3), v1, v2, v3
  9.     return (u1 % m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement