Caloogy Article
中文

The Chinese Remainder Theorem: One Theorem Holding Up Half of Cryptography

Date
Nov 11, 2025
Series
Cryptography
Reading
4 min
Topics
CRTChinese Remainder TheoremRing isomorphismRSA

The one-sentence version

If m,nm, n are coprime, then Zmn≅Zm×Zn\mathbb{Z}_{mn} \cong \mathbb{Z}_m \times \mathbb{Z}_n is a ring isomorphism: a number modulo mnmn and the pair "its remainder modulo mm, its remainder modulo nn" are the same thing. So a large problem can be split into several small ones, computed separately and combined again. RSA speedups, the Pohlig–Hellman attack, the RNS representation in fully homomorphic encryption and NTT fast multiplication all rest on it.

This article has three layers:

  1. The intuition: General Han Xin counts his soldiers
  2. Real-world use: five places the CRT appears in cryptography
  3. The mathematics: the ring isomorphism, a constructive proof, the polynomial version and a worked example

Layer 1: The Intuition

1.1 Han Xin counts his soldiers

A problem from the Sunzi Suanjing (around the 4th century):

There is an unknown number of things. Counted by threes, two remain; counted by fives, three remain; counted by sevens, two remain. How many things are there?

The answer is 2323. A popular story tells it as "Han Xin counting soldiers": have the soldiers line up in rows of three, five and seven, hear only how many are left over each time, and you can deduce the total (uniquely, below 105105).

1.2 One number, two "ID cards"

Each number from 00 to 1414 is uniquely identified by the pair "remainder when divided by 3, remainder when divided by 5":

xx 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
x mod 3x \bmod 3 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2
x mod 5x \bmod 5 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4

15 numbers, 15 different remainder pairs, in one-to-one correspondence. Better still: addition and multiplication can be done separately on each side. For example 4×7=28≡13(mod15)4 \times 7 = 28 \equiv 13 \pmod{15}; with remainder pairs:

(1,4)×(1,2)=(1⋅1 mod 3, 4⋅2 mod 5)=(1,3),(1, 4) \times (1, 2) = (1 \cdot 1 \bmod 3,\ 4 \cdot 2 \bmod 5) = (1, 3),

and the table shows that (1,3)(1, 3) is exactly 1313.

1.3 Why this is useful

The cost of big-number arithmetic grows quickly with size (multiplication costs roughly the square of the number of digits). Splitting a 2048-bit number into two 1024-bit remainders makes each side's multiplication 4 times cheaper, and the two sides can run in parallel. This is divide and conquer.


Layer 2: Real-World Use

Where it appears What the CRT does Article
RSA decryption / signing speedup Splits exponentiation modulo n=pqn = pq into modulo pp and modulo qq, 3 to 4 times faster Why RSA Decrypts Correctly
The Pohlig–Hellman attack When the group order has small factors, breaks the discrete logarithm into pieces, solves each, and recombines Diffie–Hellman and the Discrete Logarithm
Håstad's broadcast attack The same message sent to three people with e=3e = 3: the CRT combines three ciphertexts into the integer m3m^3 Why RSA Decrypts Correctly
The RNS representation in FHE A modulus of hundreds of bits, q=q0q1⋯qLq = q_0 q_1 \cdots q_L, splits into a chain of 64-bit primes, each computed directly in machine words; modulus switching just "drops one prime" Homomorphic Encryption
NTT fast polynomial multiplication The polynomial CRT: F[x]/(xn−1)≅Fn\mathbb{F}[x]/(x^n - 1) \cong \mathbb{F}^n Post-Quantum Cryptography

In addition, the analysis of Carmichael numbers in "Where Primes Come From" and the Lagrange interpolation in "Shamir's Secret Sharing" follow the same idea (Lagrange interpolation is itself the CRT over a polynomial ring).

Splitting also brings risk

If RSA-CRT makes a computation error in just one half, an attacker can factor the modulus with a single gcd⁡\gcd (the Bellcore fault attack).


Layer 3: The Mathematics

3.1 The theorem

Let m1,…,mkm_1, \dots, m_k be pairwise coprime and M=m1⋯mkM = m_1 \cdots m_k. Then the map

π:ZM→Zm1×⋯×Zmk,x↦(x mod m1,…,x mod mk)\pi: \mathbb{Z}_M \to \mathbb{Z}_{m_1} \times \cdots \times \mathbb{Z}_{m_k},\qquad x \mapsto (x \bmod m_1, \dots, x \bmod m_k)

is a ring isomorphism.

Proof sketch (the standard abstract algebra approach):

  1. First consider π~:Z→∏Zmi\tilde\pi: \mathbb{Z} \to \prod \mathbb{Z}_{m_i}, which is clearly a ring homomorphism (each component is a reduction homomorphism);
  2. Its kernel is "the numbers divisible by every mim_i", which by pairwise coprimality is MZM\mathbb{Z};
  3. By the first isomorphism theorem, Z/MZ≅im⁡π~\mathbb{Z}/M\mathbb{Z} \cong \operatorname{im}\tilde\pi;
  4. Both sides have MM elements, so injective means surjective, and it is an isomorphism.

A more general version: in a commutative ring RR, pairwise coprime ideals I1,…,IkI_1, \dots, I_k (with Ii+Ij=RI_i + I_j = R) satisfy R/(I1⋯Ik)≅R/I1×⋯×R/IkR / (I_1 \cdots I_k) \cong R/I_1 \times \cdots \times R/I_k.

3.2 How to combine again (constructing the inverse)

Let Mi=M/miM_i = M / m_i and find yi=Mi−1 mod miy_i = M_i^{-1} \bmod m_i (coprimality guarantees it exists; use the extended Euclidean algorithm). Then

x=∑iri Mi yi mod M.x = \sum_{i} r_i \, M_i \, y_i \bmod M.

The reason: ei=Miyie_i = M_i y_i is "11 modulo mim_i and 00 modulo every other mjm_j", so it is the "unit vector" of the ii-th component. This is exactly the same idea as the Lagrange basis polynomial Lj(x)L_j(x) in "Shamir's Secret Sharing".

3.3 A worked example: Han Xin's soldiers

x≡2(mod3)x \equiv 2 \pmod 3, x≡3(mod5)x \equiv 3 \pmod 5, x≡2(mod7)x \equiv 2 \pmod 7

M=105M = 105.

ii mim_i MiM_i Mi mod miM_i \bmod m_i yi=Mi−1y_i = M_i^{-1} ei=Miyie_i = M_i y_i
1 3 35 2 2 (2⋅2=4≡12\cdot 2 = 4 \equiv 1) 70
2 5 21 1 1 21
3 7 15 1 1 15

x=2⋅70+3⋅21+2⋅15=140+63+30=233≡23(mod105).x = 2 \cdot 70 + 3 \cdot 21 + 2 \cdot 15 = 140 + 63 + 30 = 233 \equiv 23 \pmod{105}.

Check: 23=7⋅3+2=4⋅5+3=3⋅7+223 = 7\cdot 3 + 2 = 4 \cdot 5 + 3 = 3 \cdot 7 + 2. ✓

In the Sunzi Suanjing mnemonic, "Three walking together, seventy is rare; five plum trees, twenty-one sprigs; seven reunited, exactly half a month; take away one hundred and five and you will know", the numbers 7070, 2121 and 1515 are exactly the eie_i in the table. (Checked with Python.)

3.4 The polynomial version

Replace Z\mathbb{Z} with F[x]F[x] and coprime integers with coprime polynomials, and the theorem still holds. If f(x)=∏i(x−αi)f(x) = \prod_i (x - \alpha_i) with the αi\alpha_i pairwise distinct, then

F[x]/(f)≅F×F×⋯×F,g(x)↦(g(α1),…,g(αn)).F[x]/(f) \cong F \times F \times \cdots \times F,\qquad g(x) \mapsto \big(g(\alpha_1), \dots, g(\alpha_n)\big).

Multiplication on the left is polynomial multiplication (convolution, slow); on the right it is pointwise (fast). This is the algebraic essence of the FFT / NTT: when the αi\alpha_i are roots of unity, both directions can be done by divide and conquer in O(nlog⁡n)O(n \log n).


Summary

Layer Key points
Intuition One number = a set of remainders; compute separately, then combine
Algebra Zmn≅Zm×Zn\mathbb{Z}_{mn} \cong \mathbb{Z}_m \times \mathbb{Z}_n, from the first isomorphism theorem
Construction Find the "unit vectors" eie_i, the same idea as Lagrange interpolation
Applications RSA speedups, Pohlig–Hellman, Håstad, RNS, NTT