Inverse Modulo Calculator
Solve inverse modulo problems step-by-step with our free calculator. See formulas, worked examples, and clear explanations.
Formula
Find x such that ax mod m = 1
The modular multiplicative inverse of a modulo m is the integer x in the range [1, m-1] such that a*x is congruent to 1 (mod m). It exists if and only if GCD(a, m) = 1. The Extended Euclidean Algorithm finds x by expressing GCD(a,m) = ax + my, and when GCD = 1, x mod m is the inverse.
Worked Examples
Example 1: Finding Modular Inverse Using Extended Euclidean Algorithm
Problem: Find the inverse of 3 modulo 11.
Solution: Extended Euclidean Algorithm:\n11 = 3 x 3 + 2\n3 = 1 x 2 + 1\n2 = 2 x 1 + 0\nBack-substitute: 1 = 3 - 1 x 2 = 3 - 1 x (11 - 3 x 3) = 4 x 3 - 1 x 11\nSo x = 4\nVerification: 3 x 4 = 12, 12 mod 11 = 1
Result: 3^(-1) mod 11 = 4 (since 3 x 4 = 12 and 12 mod 11 = 1)
Example 2: No Inverse Exists
Problem: Find the inverse of 6 modulo 9.
Solution: GCD(6, 9) = 3, which is not 1.\nSince 6 and 9 share the common factor 3, no modular inverse exists.\nFor any integer x: 6x mod 9 can only be 0, 3, or 6 (multiples of GCD).\nIt can never equal 1.
Result: No inverse exists because GCD(6, 9) = 3, not 1
Frequently Asked Questions
What is the modular multiplicative inverse?
The modular multiplicative inverse of an integer a modulo m is an integer x such that a times x is congruent to 1 modulo m, written as ax mod m equals 1. In simpler terms, it is the number you multiply a by to get a remainder of 1 when dividing by m. For example, the inverse of 3 modulo 11 is 4, because 3 times 4 equals 12, and 12 mod 11 equals 1. Not every number has a modular inverse; it exists only when a and m are coprime (their GCD is 1). The modular inverse is unique within the range 1 to m-1.
When does the modular inverse exist?
The modular multiplicative inverse of a modulo m exists if and only if a and m are coprime, meaning their greatest common divisor (GCD) is 1. If GCD(a, m) is greater than 1, no inverse exists because no integer x can make a times x leave a remainder of 1 when divided by m. For example, 4 has no inverse modulo 8 because GCD(4, 8) equals 4. However, 4 does have an inverse modulo 7 (which is 2) because GCD(4, 7) equals 1. When m is prime, every integer from 1 to m-1 has a modular inverse, which is why prime moduli are preferred in cryptography.
How does the Extended Euclidean Algorithm find the modular inverse?
The Extended Euclidean Algorithm finds integers x and y such that ax plus my equals GCD(a, m). When GCD(a, m) equals 1, this becomes ax plus my equals 1, which means ax mod m equals 1, so x is the modular inverse of a. The algorithm works by recursively applying the Euclidean algorithm while tracking the coefficients. Starting with the equation a equals q times m plus r, it back-substitutes to express the GCD as a linear combination of a and m. The final x value (taken modulo m to ensure it is positive) is the modular inverse.
How is the modular inverse used in RSA cryptography?
RSA encryption relies heavily on modular inverses. The RSA algorithm selects two large primes p and q, computes n equals p times q, and calculates the totient phi(n) equals (p-1)(q-1). A public exponent e is chosen (commonly 65537), and the private key d is computed as the modular inverse of e modulo phi(n). This means e times d mod phi(n) equals 1. The security of RSA depends on the difficulty of factoring n to find p and q, without which computing the modular inverse to obtain d is computationally infeasible. This makes modular inverses central to modern internet security.
How do you compute modular inverse by brute force?
The brute force method simply tries every integer x from 1 to m-1 and checks whether a times x mod m equals 1. This is conceptually the simplest approach and works correctly for any valid inputs. For example, to find the inverse of 3 mod 7: try 1 (3 mod 7 = 3), try 2 (6 mod 7 = 6), try 3 (9 mod 7 = 2), try 4 (12 mod 7 = 5), try 5 (15 mod 7 = 1) - found it, inverse is 5. However, brute force has time complexity O(m), making it impractical for large moduli used in cryptography where m can have hundreds of digits.
What is a modular inverse table and why is it useful?
A modular inverse table lists the multiplicative inverse of every element in a given modular system. For modulus m, it maps each integer a (where GCD(a, m) equals 1) to its inverse x such that ax mod m equals 1. When m is prime, every non-zero element has an inverse, creating a complete table. These tables are useful for quick lookups in repeated calculations, educational purposes to see patterns in modular arithmetic, and verifying algorithm implementations. For small prime moduli, the table reveals symmetries and structure of the multiplicative group of integers modulo m.