Calculate The Inverse Mod N
The inverse mod n calculator helps you find the modular inverse of a number a modulo n, which is a number x such that (a × x) ≡ 1 mod n. This is useful in cryptography, number theory, and computer science applications.
What is the inverse mod n?
The modular inverse of a number a modulo n is a number x that satisfies the equation:
a × x ≡ 1 mod n
This means that when a is multiplied by x, the result is congruent to 1 modulo n. The modular inverse exists only if a and n are coprime (their greatest common divisor is 1).
For example, the inverse of 3 modulo 11 is 4 because 3 × 4 = 12, and 12 mod 11 is 1.
How to calculate the inverse mod n
To find the modular inverse of a modulo n, you can use the Extended Euclidean Algorithm, which efficiently finds integers x and y such that:
a × x + n × y = gcd(a, n)
If the greatest common divisor (gcd) of a and n is 1, then x is the modular inverse of a modulo n. If the gcd is not 1, then the modular inverse does not exist.
Step-by-step method
- Calculate the gcd of a and n using the Euclidean algorithm.
- If gcd(a, n) ≠ 1, then the modular inverse does not exist.
- If gcd(a, n) = 1, use the Extended Euclidean Algorithm to find x and y.
- The value of x (mod n) is the modular inverse of a modulo n.
For negative results, you can add n to get a positive equivalent.
Examples of inverse mod n
Example 1: Find the inverse of 3 mod 11
Using the Extended Euclidean Algorithm:
- 11 = 3 × 3 + 2
- 3 = 2 × 1 + 1
- 2 = 1 × 2 + 0
Working backwards:
- 1 = 3 - 2 × 1
- 2 = 11 - 3 × 3
- 1 = 3 - (11 - 3 × 3) × 1 = 4 × 3 - 11
The coefficient of 3 is 4, so the inverse of 3 mod 11 is 4.
Example 2: Find the inverse of 5 mod 7
Using the Extended Euclidean Algorithm:
- 7 = 5 × 1 + 2
- 5 = 2 × 2 + 1
- 2 = 1 × 2 + 0
Working backwards:
- 1 = 5 - 2 × 2
- 2 = 7 - 5 × 1
- 1 = 5 - (7 - 5 × 1) × 2 = 3 × 5 - 7 × 2
The coefficient of 5 is 3, so the inverse of 5 mod 7 is 3.
Applications of modular inverses
Modular inverses have several important applications in mathematics and computer science:
- Cryptography: Used in RSA encryption and digital signatures.
- Number Theory: Essential for solving linear congruences and Diophantine equations.
- Computer Science: Used in hashing algorithms and error detection codes.
- Finite Fields: Used in constructing finite fields for algebraic geometry.
Understanding modular inverses is fundamental for working with modular arithmetic and its applications in various fields.
FAQ
What is the difference between a regular inverse and a modular inverse?
The regular inverse of a number a is 1/a, which exists for all non-zero numbers. The modular inverse exists only if a and n are coprime, and it satisfies a × x ≡ 1 mod n.
How do I know if a modular inverse exists?
A modular inverse exists if and only if the greatest common divisor (gcd) of a and n is 1. If gcd(a, n) ≠ 1, then the modular inverse does not exist.
Can the modular inverse be negative?
Yes, the modular inverse can be negative. However, it's common to express the result as a positive number by adding n to the negative result.