Search code examples
cryptographyinversemodular

How to get the modular inverse by using Extended Eucledian Algorithm?


Given a mod b and find its inverse, then doing the extended GCD.

ax + by = gcd(a,b)

After I get x and y, how do I get its inverse?


Solution

  • If gcd(a,b) != 1, a does not have an inverse mod b.

    Otherwise ax + by = 1, which means that ax = 1 (mod b), so x is the inverse of a mod b.