← Back to section · Foundations of Cryptography

Number-Theory Roots: The Two Pillars of Classical Public-Key Cryptography

Starting from modular arithmetic and Euler's theorem, see why integer factorisation and the discrete logarithm are the shared foundation of RSA and Diffie–Hellman — with hand-worked small examples and a glimpse of the Chinese remainder theorem.

Published 22 November 2026 · 7 min read · PQ Frontier

Number-Theory Roots: The Two Pillars of Classical Public-Key Cryptography
AI-generated illustration by PQ Frontier
Video explainer · Number theory: primes and modular arithmetic

Any discussion of post-quantum cryptography should start by being precise about what classical public-key cryptography actually stands on. The answer is surprisingly concentrated: almost everything rests on two number-theoretic problems — factorising large integers and computing discrete logarithms. This article assembles the needed background in one place: modular arithmetic, Euler’s theorem, where the hardness of the two problems comes from, and the Chinese remainder theorem that pervades implementations.

Modular arithmetic: arithmetic on a clock

Arithmetic modulo nn keeps only remainders: a mod na \bmod n is the remainder of aa upon division by nn, and every computation can be folded back into {0,1,…,n−1}\{0, 1, \dots, n-1\}. A clock is the everyday model: 23:00 plus 5 hours is 04:00, i.e. 23+5≡4(mod24)23 + 5 \equiv 4 \pmod{24}.

Addition, subtraction and multiplication work without friction in this world; “division” is conditional. An element aa has a modular inverse (an a−1a^{-1} with a⋅a−1≡1(modn)a \cdot a^{-1} \equiv 1 \pmod n) if and only if gcd⁡(a,n)=1\gcd(a, n) = 1. For example, modulo 7, 3−1=53^{-1} = 5 because 3×5=15≡1(mod7)3 \times 5 = 15 \equiv 1 \pmod 7; modulo 6, neither 2 nor 3 has an inverse, since they share factors with 6. Key generation and signature verification are, at bottom, repeated inversion and exponentiation in this modular world.

Euler’s theorem: the periodicity of powers

There are φ(n)\varphi(n) integers coprime to nn (Euler’s totient); for n=pqn = pq a product of two distinct primes, φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1). Euler’s theorem states that if gcd⁡(a,n)=1\gcd(a, n) = 1, then aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod n. A small check: with n=10n = 10, φ(10)=4\varphi(10) = 4, and 34=81≡1(mod10)3^4 = 81 \equiv 1 \pmod{10} — it holds.

RSA’s correctness is a direct corollary. Take n=pqn = pq, choose ee coprime to φ(n)\varphi(n), and compute d≡e−1(modφ(n))d \equiv e^{-1} \pmod{\varphi(n)}; then for every message mm, (me)d≡m(modn)(m^e)^d \equiv m \pmod n — encryption followed by decryption returns the original. Security rests on a different fact: an outsider who knows only nn and ee must recover φ(n)\varphi(n) to find dd, and computing φ(n)\varphi(n) is exactly as hard as factorising nn.

Pillar one: integer factorisation

Splitting a 2048-bit composite n=pqn = pq back into its two prime factors is, with the best known classical algorithm — the number field sieve — a subexponential task, of complexity roughly exp⁡(O((ln⁡n)1/3(ln⁡ln⁡n)2/3))\exp(O((\ln n)^{1/3}(\ln\ln n)^{2/3})). That “subexponential” matters: it forces RSA key lengths to keep growing with computing power, at worsening efficiency — a 2048-bit RSA operation is already far more expensive than symmetric cryptography of comparable strength. Public factorisation records have sat at the hundreds-of-digits scale for over a decade, not because the problem suddenly became harder, but because the subexponential curve is still steep enough at current sizes.

The public record makes this concrete: the standing factorisation record is RSA-250 (829 bits, 250 decimal digits), completed in 2020 at a cost of a few thousand core-years of number-field-sieve computation; before that, the 768-bit record stood for a full decade. The record curve teaches two things. First, factoring capability climbs steadily and the long-tail risk is real, which is why recommended RSA lengths in NIST and national guidance have marched from 1024 to 2048, with 3072 listed for long-term use. Second, the climb is far slower than exponential growth: “classical computers factor 2048-bit moduli by brute compute” remains out of reach for the foreseeable future — RSA’s classical security is being eroded record by record, not broken overnight.

Pillar two: the discrete logarithm

In the multiplicative group modulo a prime pp, computing gx mod pg^x \bmod p for a generator gg is fast — repeated squaring takes O(log⁡x)O(\log x) multiplications. The reverse problem, given gg and gx mod pg^x \bmod p find xx, is the discrete logarithm problem. A hand-sized example: modulo 11, 27=128≡7(mod11)2^7 = 128 \equiv 7 \pmod{11}, so the discrete logarithm of 7 to base 2 is 7 — trivially found by table at this size; at 2048 bits, the best classical algorithms are again subexponential index-calculus methods.

Diffie–Hellman key exchange, DSA and Schnorr signatures all stand on the discrete logarithm. Move the group to the points of an elliptic curve and you obtain ECDLP (the subject of our companion article on elliptic curves) — the group changes; the structure of the problem does not.

A glimpse of the Chinese remainder theorem

If moduli are pairwise coprime, the residues modulo each of them combine into a unique solution modulo their product. Example: x≡2(mod3)x \equiv 2 \pmod 3, x≡3(mod5)x \equiv 3 \pmod 5, x≡2(mod7)x \equiv 2 \pmod 7 gives x≡23(mod105)x \equiv 23 \pmod{105} (check: 23=3×7+223 = 3\times7+2, 23=5×4+323 = 5\times4+3, 23=7×3+223 = 7\times3+2 — all correct). The CRT is everywhere in cryptographic engineering: RSA private-key operations use it to split one exponentiation modulo nn into two smaller ones modulo pp and qq, gaining roughly a factor of four in speed — while also opening the door to fault attacks, a classic case of “mathematically elegant, handle with care in implementation.”

The pillars’ raw material: where large primes come from

Both pillars presuppose that large primes are already in hand: RSA must generate two thousand-bit primes on the spot, and Diffie–Hellman group parameters are likewise rooted in a large prime. But deciding whether a 1024-bit odd number is prime cannot be done by trial division — there are on the order of 25122^{512} candidate divisors. The workable route is probabilistic primality testing. The simplest is the Fermat test: if an−1≢1(modn)a^{n-1} \not\equiv 1 \pmod n, then nn is certainly composite; but Carmichael numbers — composites that lie to every coprime base — defeat it. The engineering standard is the Miller–Rabin test: write n−1=2s⋅dn-1 = 2^s \cdot d and check a chain of square roots for random bases. Its criterion is strictly stronger than Fermat’s and admits no universal liars — a composite passes each round with probability at most 1/41/4, so 40 independent rounds push the error below 2−802^{-80}, lower than the probability of a hardware bit flip. “Generating a prime” thus becomes a pipeline: draw a large random odd number, sieve out obvious composites with small primes, then run Miller–Rabin rounds; the expected number of attempts follows from the prime number theorem (near 210242^{1024}, a random odd number is prime with probability about 2/(1024ln⁡2)2/(1024 \ln 2) — a few hundred tries per prime on average). There is a further engineering refinement: DH groups prefer safe primes p=2q+1p = 2q + 1 with qq also prime, leaving no small subgroups for Pohlig–Hellman-style attacks, while RSA primes must avoid structural weaknesses such as smooth p−1p-1 or p+1p+1. The AKS test (2002) proved primality has a deterministic polynomial-time algorithm, yet production systems still use probabilistic tests — speed and confidence both suffice, and theoretical completeness is simply not on the requirements list. The detail is a miniature of the two pillars themselves: the security of classical public-key cryptography comes half from the hard problems, and half from these repeatedly validated number-theoretic engineering conventions.

Why both pillars fall together

Factorisation and discrete logarithms look unrelated, yet in 1994 Shor’s algorithm showed they are the same kind of problem: both reduce to finding a period in an abelian group (the hidden subgroup problem), and the quantum Fourier transform extracts exactly such periods efficiently. Once a fault-tolerant quantum computer exists, RSA, Diffie–Hellman, DSA and all elliptic-curve schemes fail simultaneously — not because of an implementation bug, but because the foundation is removed. The entire post-quantum programme is the search for new problems that do not stand on these two pillars and have no known quantum shortcut: lattices, hashes, error-correcting codes. Understanding the pillar structure is what makes clear that the migration is a change of foundation, not a patch.

References

  • Rivest, Shamir & Adleman, A method for obtaining digital signatures and public-key cryptosystems, Communications of the ACM 21, 120 (1978). https://doi.org/10.1145/359340.359342
  • Diffie & Hellman, New directions in cryptography, IEEE Transactions on Information Theory 22, 644 (1976). https://doi.org/10.1109/TIT.1976.1055638
  • Shoup, A Computational Introduction to Number Theory and Algebra, 2nd ed., Cambridge University Press (2008) (author’s free edition). https://shoup.net/ntb/
  • Hardy & Wright, An Introduction to the Theory of Numbers, 6th ed., Oxford University Press (2008).
  • Shor, Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer, SIAM Journal on Computing 26, 1484 (1997). https://doi.org/10.1137/S0097539795293172

Tags: number theoryRSAdiscrete logarithm