Chinese Remainder Theorem
The Chinese Remainder Theorem (CRT) is a mathematical theorem that states that if we have a system of linear congruences (equations of the form "x ā” a mod m
") with pairwise coprime moduli, then there exists a unique solution for x
modulo the product of the moduli.
The theorem is called "Chinese" because it was first stated by the ancient Chinese mathematician Sun Tzu Suan Ching.
The CRT is particularly useful in solving systems of simultaneous modular equations that are difficult or impossible to solve individually. For example, if we have two congruences:
It is not possible to find a single solution for x
that satisfies both congruences.
However, using the CRT, we can find a unique solution for x
that satisfies both congruences modulo the product of the moduli (20
).
The CRT has many applications in cryptography, number theory, and computer science. For example, it is used in RSA encryption to speed up the calculation of the modular inverse, and in constructing public-key cryptosystems based on integer factorization.
Algorithm
In order to calculate a solution, two variables are needed :
The Ei
values are composed multiplying all the n_values each others except n at position i
.
For each elements of E
, the inverse (mod ni
) y
can be calculated using the Fermat's Little theorem :
Then a solution for x can be calculated using the following equation :
The unique solution is then x % N
Python
Resources
Last updated