Modular Inverses and the Chinese Remainder Theorem
You can't divide mod n, but you can multiply by an inverse: a number b with ab ≡ 1 (mod n). It exists exactly when a and n share no factor, and Euclid's algorithm finds it. The Chinese remainder theorem then says that remainders by coprime moduli pin down a number uniquely.
What the symbols mean
- Inverse of a
The number that multiplies with a to give 1 mod n.
- Modulus
The number you're working mod.
Explanation
A modular inverse is simply the number that undoes multiplication on a clock: the inverse of is whatever you multiply by to get back to 1. It's called an "inverse" for the same reason is the inverse of 3 in ordinary arithmetic, except mod there are no fractions, so the inverse has to be a whole number. It's how you "divide" in modular arithmetic, and it's the secret ingredient of RSA in the next lesson. The formula just says (your number) times (its inverse) lands on 1, and the condition (a and n share no common factor) tells you when that's possible. That's the whole lesson in one line.
In the last lesson you saw that you can add and multiply mod freely, but division was missing. In ordinary arithmetic, dividing by 3 is the same as multiplying by , the number that turns 3 into 1. So the question is whether mod there's a whole number that turns into 1.
Finding an inverse. For small , just search: , so . For big , Euclid's algorithm from two lessons ago does the work. If , Bézout gives . Now look at that mod : the term is a multiple of , so it disappears, leaving . So is the inverse, and the extended Euclidean algorithm hands it to you.
What if ? Then and are both multiples of , so reduced mod is still a multiple of , and it can never be . So 6 has no inverse mod 9: every multiple of 6 lands on 0, 3 or 6.
Solving . With an inverse in hand, this works just like solving : multiply both sides by to get . For : .
Chinese remainder theorem. It's named for the Chinese mathematician Sunzi, who posed a puzzle of this kind about 1,700 years ago (you'll meet it in the practice). If and are coprime, the system , has exactly one solution mod . Here's a way to see why. There are numbers from 0 to , and possible pairs of remainders. Two numbers in that range with the same pair would differ by a multiple of both and , so a multiple of (since they share no factor), and that's impossible unless they're equal. So every pair of remainders shows up exactly once. For and , listing (the numbers ) finds : so .
See it
Worked examples
Solve .
- 1
Since , 4 has an inverse. The modulus is small, so search: , so .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Find the inverse of 3 mod 11.
Solve for between 0 and 6.
Does 6 have an inverse mod 9?
Find the smallest positive with and .
A basket of eggs leaves 2 over when counted by threes, 3 over when counted by fives, and 2 over when counted by sevens. What is the fewest eggs it can hold?
An affine cipher encrypts letters as . Decrypting needs the inverse of 7 mod 26. Find it.
The hardest one here. Get it, and you've got this lesson.
Solve . Enter every solution from 0 to 20.
Where it's used
RSA's private key is a modular inverse, and implementations use the Chinese remainder theorem to decrypt about four times faster.