Modular Inverse Calculator
Find the modular multiplicative inverse of a number a modulo m with the extended Euclidean algorithm and a check. An inverse of a modulo m exists exactly when GCD(a, m) = 1. Example: with number a 3, modulus m 11, the result is 3⁻¹ mod 11 = 4.
Last updated · By S. Dilshan · Runs in your browser, nothing is uploaded
Step-by-Step Solution
How do you use the Modular Inverse Calculator?
Enter a number a and a modulus m. The calculator uses the extended Euclidean algorithm to find x such that a × x ≡ 1 (mod m), or tells you that no inverse exists when a and m share a factor.
What formula does the Modular Inverse Calculator use?
An inverse of a modulo m exists exactly when GCD(a, m) = 1. The extended Euclidean algorithm finds integers x and y with a·x + m·y = 1; then a⁻¹ ≡ x (mod m), reduced into 0 … m − 1. For prime m, Fermat’s little theorem also gives a⁻¹ ≡ a^(m−2) (mod m).
Worked example: Number a 3, Modulus m 11
The inverse of 3 modulo 11 is 4, because 3 × 4 = 12 ≡ 1 (mod 11). The Bézout identity is 3 × 4 + 11 × (−1) = 1. In contrast 6 has no inverse modulo 9, since GCD(6, 9) = 3.
With the default values the calculator returns 3⁻¹ mod 11 = 4; Check = 3 × 4 mod 11 = 1; Bézout coefficients = 3 × 4 + 11 × -1 = 1; GCD = 1.
Where Is This Calculation Used?
Modular inverses are used to solve linear congruences ax ≡ b (mod m), in RSA key generation (the private exponent is the inverse of e modulo φ(n)), in the Chinese remainder theorem and in hashing and error-correcting codes.
What are the most common mistakes with the Modular Inverse Calculator?
- Looking for an inverse when a and m are not coprime.
- Giving a negative representative instead of reducing into 0 … m − 1.
- Confusing the modular inverse with the ordinary reciprocal 1/a.
What Is the Tested Example for the Default Values?
This example is computed by the same code that powers the calculator above, so you can compare it with your own numbers or a textbook answer.
| Input: Number a | 3 |
|---|---|
| Input: Modulus m | 11 |
| 3⁻¹ mod 11 | 4 |
| Check | 3 × 4 mod 11 = 1 |
| Bézout coefficients | 3 × 4 + 11 × -1 = 1 |
| GCD | 1 |
Where Can You Verify These Formulas?
The definitions and formulas on this page follow standard references. Check them against these sources:
Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.
Frequently Asked Questions
What is a modular multiplicative inverse?
A number x such that a × x leaves remainder 1 when divided by m, written a⁻¹ mod m.
When does a modular inverse exist?
Exactly when a and m are coprime, meaning their GCD is 1.
How do you find a modular inverse by hand?
Run the extended Euclidean algorithm on (a, m) and read off the coefficient of a in a·x + m·y = 1.