← Back to section · Foundations of Cryptography
The Chinese Remainder Theorem: Splitting Big Problems into Small Congruences
Starting from the classic counting problem in the Sunzi Suanjing, this article states the Chinese remainder theorem, sketches its constructive proof and uniqueness condition, and shows why it appears in settings as different as RSA acceleration and polynomial interpolation.
“There is a quantity whose number is unknown. Counted in threes, two remain; counted in fives, three remain; counted in sevens, two remain. How many are there?” This problem from the Sunzi Suanjing is the most famous congruence problem in the history of mathematics: find a number that leaves remainder 2 modulo 3, remainder 3 modulo 5, and remainder 2 modulo 7. The answer 23 is only the smallest positive solution; the real theorem says far more. It asserts existence and uniqueness for an entire class of problems and gives a mechanical construction. More than a millennium old, this theorem still works silently inside every RSA signature a chip produces today.
The statement: coprimality is the key condition
Let be pairwise coprime. For any remainders , the system always has a solution, and any two solutions differ by a multiple of — that is, the solution is unique modulo . The pairwise-coprime condition cannot be dropped: with non-coprime moduli the system may have no solution at all (for instance and contradict each other), or uniqueness may hold only modulo the least common multiple. Coprimality guarantees that the information carried by each modulus overlaps with none of the others, so the pieces fit together seamlessly.
The construction: build bricks, then assemble
The proof is itself an algorithm. Let ; since is coprime to , it has an inverse modulo . Consider : it is divisible by every other () yet is congruent to 1 modulo — a brick that is “lit” only at the -th modulus and dark elsewhere. Then solves the system: looked at modulo , only the -th term survives and contributes exactly ; all other terms vanish. In the Sunzi example, and the three bricks are 70, 21 and 15, giving . The mnemonic verses of the ancient text record precisely these bricks. From another angle, the theorem establishes an isomorphism between the ring and the direct product of the rings : a number modulo and the tuple of its residues modulo the small moduli can be translated back and forth without loss.
It is worth recording the Chinese mathematical tradition’s role in completing the theorem. The Sunzi Suanjing gave only a mnemonic recipe for specific numbers; it was Qin Jiushao in the Southern Song dynasty, in his Mathematical Treatise in Nine Sections, who supplied the general constructive algorithm — the “Dayan Qiuyi” method for finding each brick’s inverse by a repeated-division procedure — and who also treated the reduction needed when moduli are not fully coprime. This body of work predates comparable European systematisation by centuries, and the word “Chinese” in the theorem’s modern name commemorates exactly that complete chain from concrete recipe to general algorithm. From mnemonic to algorithm to isomorphism, the same theorem has lived three lives at three levels of abstraction.
Speed in RSA — and its risk
An RSA private-key operation is an exponentiation modulo with a huge exponent and modulus. With CRT, the key holder exponentiates separately modulo and modulo — modulus and exponent both halved — and then uses the theorem to stitch the two results back into the answer modulo . Since modular exponentiation costs roughly the cube of the size, two half-size computations plus one stitching cost about a quarter of the direct computation, and in practice decryption and signing run about four times faster; virtually every RSA implementation enables this optimisation by default. The other side of the coin: if one of the two CRT branches computes a wrong result — even from a transient hardware fault — the difference between the faulty and correct outputs leaks information about and , and a single gcd computation lets an attacker factor . This is the famous fault-injection attack, and implementers must verify a CRT result before releasing it. The theorem itself is flawless; the danger lies in how it is used.
Non-coprime moduli are not hopeless either, but the conclusion must be restated: the pair , has a solution if and only if — the two remainders must agree on the common factor — and when a solution exists it is unique modulo . Qin Jiushao’s handling of such cases was to first “reduce” the moduli by their common factors into a coprime set, then apply the standard construction. This generalisation is not rare in engineering: any problem that merges several periodic constraints (rotation cycles of different granularity, aligning timestamps from different sources) is, at bottom, solving a system of congruences that need not be coprime, and the fixed safe routine is to check consistency first and merge second.
The CRT parameters sitting inside a private-key file
Open an RSA private key in PKCS#1 format and, besides the modulus and the public and private exponents, you will find three extra parameters: , and . The first two come from Fermat’s little theorem: when exponentiating modulo , the exponent may first be reduced modulo , so each half-size branch gets a shortened exponent as well. The third is the key to the stitching step: with branch results and , Garner’s formula gives , completing the merge with a single multiplication and reduction — cheaper than the generic CRT construction. Precomputing and storing these three parameters amortises the theorem’s construction once, at key generation, so that every later private-key operation takes the shortest path directly. The extra bulk of a private-key file over a public one is exactly this CRT parameter set — a reminder to custodians that no part of a private-key file is a minor leak: if or escapes, the factorisation can be derived from it just the same.
It is worth noting that CRT requires the moduli to be pairwise coprime, which RSA’s distinct primes satisfy naturally. Conversely, anyone who carelessly applies the CRT formulas with non-coprime moduli gets a result that is silently wrong on some residues and hard to detect — the theorem’s hypotheses are never decoration, and every “skipped check” in an implementation opens the door to precisely this kind of silent error.
Echoes beyond number theory
The same “decompose — solve independently — reassemble losslessly” pattern recurs across many fields: over polynomial rings it becomes Lagrange interpolation (values at enough points determine a low-degree polynomial uniquely); in signal processing it appears as multirate decomposition; in distributed computing as splitting a large task across machines and merging results. The Chinese remainder theorem is therefore not just a fact of number theory but a general strategy for decoupling coupled problems: as long as the sub-problems’ information channels do not interfere, local solutions assemble into a global one. Once you have internalised it, a great deal of algorithm design starts to look familiar.
Tags: number theoryChinese remainder theoremcongruencesRSA