Assume we want to find a % n. Let n = p1 * p2. Find a % p1 and a % p2. Call a % p1 = x1 Call a % p2 = x2; For finding a % n. We can do following. Write a % n = x1 * alpha1 + x2 * alpha2;
How to find alpha1 and alpha2 and how to prove that a % n = x1 * alpha1 + x2 * alpha2 ?
Are p1 and p2 distinct primes?
yes
Well in that case you are looking for the Chinese Remainder Theorem. It was not clear to me how to use it to solve specific cases, so I will try to explain my best here.
You are trying to find a such that
Unable to parse markup [type=CF_TEX]
(mod p1)Unable to parse markup [type=CF_TEX]
(mod p2)The solution then is:
Unable to parse markup [type=CF_TEX]
Here is what each value means:
Unable to parse markup [type=CF_TEX]
Unable to parse markup [type=CF_TEX]
The value
Unable to parse markup [type=CF_TEX]
means "the modular multiplicative inverse of N1 with respect to p1". Formally, this means that:Unable to parse markup [type=CF_TEX]
(mod p1)Similarly,
Unable to parse markup [type=CF_TEX]
means "the modular multiplicative inverse of N1 with respect to p2"Unable to parse markup [type=CF_TEX]
(mod p2)How do we find
Unable to parse markup [type=CF_TEX]
andUnable to parse markup [type=CF_TEX]
? We can use Fermat's Little Theorem to compute the modular multiplicative inverse of a number with respect to a prime.We have
Unable to parse markup [type=CF_TEX]
(mod p)Dividing both sides by a we get
Unable to parse markup [type=CF_TEX]
(mod p)Again
Unable to parse markup [type=CF_TEX]
(mod p)Therefore, the modular multiplicative inverse of N1 with respect to p1 is equal to
Unable to parse markup [type=CF_TEX]
. (Note: this value can get very very large, the value you really want isUnable to parse markup [type=CF_TEX]
mod p1)Similarly,
Unable to parse markup [type=CF_TEX]
(Again, this value is usually gigantic, so you computeUnable to parse markup [type=CF_TEX]
mod p2)Now that you have all the variables, you can compute a mod n.
Please let me know if anything is unclear/wrong. That's it!