Inverse Modulo Calculator
Solve inverse modulo problems step-by-step with our free calculator. See formulas, worked examples, and clear explanations.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Inverse Modulo Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: Find x such that ax mod m = 1
Worked example โ 3^(-1) mod 11 = 4 (since 3 x 4 = 12 and 12 mod 11 = 1)
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: 11 = 3 x 3 + 2 3 = 1 x 2 + 1 2 = 2 x 1 + 0 Back-substitute: 1 = 3 - 1 x 2 = 3 - 1 x (11 - 3 x 3) = 4 x 3 - 1 x 11 So x = 4 Verification: 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. Since 6 and 9 share the common factor 3, no modular inverse exists. For any integer x: 6x mod 9 can only be 0, 3, or 6 (multiples of GCD). It 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.
What is Fermat Little Theorem and how does it relate to modular inverses?
Fermat Little Theorem states that if p is a prime number and a is not divisible by p, then a raised to the power (p-1) is congruent to 1 modulo p. This provides an alternative method to compute modular inverses when the modulus is prime: the inverse of a modulo p equals a raised to the power (p-2) modulo p. For example, the inverse of 3 modulo 11 is 3 to the 9th mod 11, which equals 19683 mod 11 equals 4. This method uses modular exponentiation and is computationally efficient, though the Extended Euclidean Algorithm is generally preferred for its broader applicability.
What is Euler theorem and how does it generalize modular inverses?
Euler theorem generalizes Fermat Little Theorem to non-prime moduli. It states that if a and m are coprime, then a raised to the power phi(m) is congruent to 1 modulo m, where phi(m) is Euler totient function counting integers from 1 to m that are coprime to m. This gives the modular inverse as a raised to phi(m) minus 1 modulo m. For prime m, phi(m) equals m minus 1, recovering Fermat result. For composite moduli, you compute phi using the prime factorization. This theorem is foundational in number theory and underpins RSA key generation.
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 are practical applications of modular inverses beyond cryptography?
Modular inverses appear in many computational contexts. In competitive programming, they are essential for computing combinations modulo a prime using the formula C(n,k) mod p, which requires the inverse of k factorial. In error-correcting codes like Reed-Solomon, modular inverses over finite fields enable data recovery. In hash table design, modular arithmetic with inverses helps distribute keys uniformly. The Chinese Remainder Theorem reconstruction requires modular inverses. In computer graphics, modular inverses help with cyclic indexing and wraparound calculations. They also appear in scheduling algorithms and clock arithmetic.
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.
How does modular inverse relate to division in modular arithmetic?
In regular arithmetic, dividing by a number is the same as multiplying by its reciprocal. Similarly, in modular arithmetic, dividing by a modulo m means multiplying by the modular inverse of a. Since fractions do not exist in modular arithmetic (results must be integers), the modular inverse serves as the equivalent of division. For example, to compute 5 divided by 3 modulo 7, find the inverse of 3 mod 7 (which is 5) and multiply: 5 times 5 mod 7 equals 25 mod 7 equals 4. This concept is critical in finite field arithmetic used in coding theory and elliptic curve cryptography.
References
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐งฎMultiplicative Inverse Modulo Calculator
Calculate multiplicative inverse modulo with inputs, formulas, and instant results.
๐งฎInverse Function Calculator
Calculate inverse function with inputs, formulas, and instant results.
๐งฎInverse Variation Calculator
Calculate inverse variation with inputs, formulas, and instant results.
๐งฎModulo Calculator
Calculate modulo with inputs, formulas, and instant results.
๐งฎMultiplicative Inverse Calculator
Calculate multiplicative inverse with inputs, formulas, and instant results.
๐งฎInverse Of4x4matrix Calculator
Calculate inverse of4x4matrix with inputs, formulas, and instant results.
๐งฎInverse Matrix Calculator
Calculate inverse matrix with inputs, formulas, and instant results.
๐งฎInverse Trigonometric Functions Calculator
Calculate inverse trigonometric functions with inputs, formulas, and instant results.