Part IV: Number Theory and Cryptography
"Mathematics is the queen of the sciences, and number theory is the queen of mathematics." — commonly attributed to Carl Friedrich Gauss
For most of its history, number theory was the proudest example of mathematics done for its own sake. The properties of whole numbers — which ones are prime, how they divide one another, what remainders they leave — were studied because they were beautiful, not because anyone expected them to do anything. In 1940 the number theorist G. H. Hardy went so far as to celebrate the field's uselessness, confident that nothing so pure could ever be put to a practical, let alone a military, end. He was spectacularly wrong. The "useless" branch of mathematics turned out to be the thing that secures the entire internet. Every time your browser shows a padlock, every time you send a password or a payment, you are trusting a theorem about prime numbers that Hardy would have recognized.
That reversal is the story of this part. We start where Gauss did — with divisibility, primes, and the humble question of what happens when one integer fails to divide another — and we build, brick by brick, toward a working implementation of RSA, the public-key cryptosystem that made secure communication between strangers possible. Along the way the abstraction earns its keep: the same modular arithmetic that lets two people who have never met agree on a secret key also powers the hash tables in your standard library and the error-correcting codes that keep a scratched DVD playable and a deep-space transmission intelligible. By the end you will not just understand how these systems work; you will have built the core of one yourself.
This is the payoff part of the book for the RSA anchor we have been quietly seeding since Part I. Divisibility first appeared in the proof chapters; primes showed up in a classic contradiction argument; keyspace sizing made a cameo in counting. Here those scattered threads converge into a single, coherent engine. The reward for the abstraction is concrete and immediate: cryptography is the rare topic where a few clean theorems translate, almost line for line, into code that protects real secrets.
What You Will Learn
Chapter 22: Number Theory Foundations lays the groundwork. You will reason rigorously about divisibility, compute greatest common divisors with the Euclidean algorithm (one of the oldest algorithms still in daily use), and extend it via Bézout's identity to express a gcd as a combination of its inputs. The chapter closes with the Fundamental Theorem of Arithmetic — the guarantee that every integer factors into primes in exactly one way — which is quietly responsible for everything that follows.
Chapter 23: Modular Arithmetic introduces the "clock arithmetic" that is the literal engine of RSA. You will learn the rules of congruence, solve linear congruences, and compute modular inverses, then meet two theorems that make public-key cryptography possible: the Chinese Remainder Theorem and Fermat's and Euler's theorems on exponents. You will also learn fast modular exponentiation — how to raise a number to an astronomical power, modulo $n$, without ever computing the astronomical number.
Chapter 24: Algebraic Structures — Groups, Rings, and Fields steps up a level of abstraction to explain why the previous chapter's machinery works. You will define groups, rings, and fields, verify their axioms, and work inside $\mathbb{Z}_n$ and the finite fields $\mathrm{GF}(p)$ and $\mathrm{GF}(2^n)$. This is the deepest, most abstract chapter in the part, but it pays for itself twice: it reveals the structure beneath RSA's correctness, and it supplies the algebra that error-correcting codes will need later in the book.
Chapter 25: Cryptography — From Caesar Cipher to RSA is the destination. You will see why classical ciphers fail, understand the key-exchange problem that public-key cryptography solves, and then implement RSA end to end: key generation, encryption, and decryption. Crucially, you will prove that RSA works (a short, satisfying argument resting on Euler's theorem) and understand why it is secure (the conjectured hardness of factoring large numbers). This is the chapter where number theory becomes a tool you can wield.
Chapter 26: Hashing, Checksums, and Error Detection turns the same arithmetic toward a different goal: data integrity. You will design and analyze hash functions, see precisely why collisions are unavoidable, and build the checksums and cyclic redundancy checks that guard every file transfer and network packet. The chapter draws a sharp line between detecting an error and correcting one — a distinction the final part of the book will develop into full error-correcting codes.
How This Part Fits
This part is where the first three parts cash out. The proof techniques of Part I are not optional background here — they are the working tools of the chapters. Number theory is the most proof-dense material in the book, and you will lean directly on direct proof and proof by contraposition (Chapter 4), proof by contradiction (Chapter 5 — the infinitude of primes is the canonical example), and mathematical induction (Chapter 6) to establish results you then turn into code. From Part III, the counting principles return in two places: the keyspace and brute-force sizing arguments from Chapter 15 explain why a cryptographic key must be large, and the pigeonhole principle from Chapter 17 explains why hash collisions are a mathematical certainty, not an engineering oversight.
Looking forward, Part IV sets up two later destinations. The algebraic structures of Chapter 24 and the error-detection ideas of Chapter 26 combine in Chapter 38 to build genuine error-correcting codes over finite fields. And the RSA implementation you complete in Chapter 25 becomes Track A of the capstone in Chapter 39, where the dmtoolkit package you have been assembling all along — now including a numbertheory and a crypto module — is wired into a complete encryption system. The question of why breaking RSA is believed to be hard, finally, points toward the complexity theory of Chapter 37 and the deepest open problem in computer science.
Time Investment
| Chapter | Title | Difficulty | Estimated Time |
|---|---|---|---|
| 22 | Number Theory Foundations | Intermediate | 6–7 hours |
| 23 | Modular Arithmetic | Intermediate | 6–7 hours |
| 24 | Algebraic Structures — Groups, Rings, and Fields | Advanced | 7 hours |
| 25 | Cryptography — From Caesar Cipher to RSA | Advanced | 7–8 hours |
| 26 | Hashing, Checksums, and Error Detection | Intermediate | 6 hours |
| Part total | ≈ 32–35 hours |
The two intermediate foundation chapters (22 and 23) are the load-bearing ones; do not rush them, because everything after depends on the gcd and modular-exponentiation machinery you build there. Chapter 24 is the abstraction peak — budget for it accordingly — and Chapter 25 is the payoff that makes the climb worth it. Chapter 26 is more self-contained and can be read on its own if your interest is data integrity rather than cryptography.
We begin, fittingly, with the single most basic question one can ask about two integers: does one of them divide the other, and if not, what is left over? Chapter 22 shows that this elementary question — and the ancient algorithm that answers it — is the foundation on which the security of the modern internet is built.