Abstract algebra studies structures: a set together with one or more operations that obey a short list of rules. Instead of asking "what is 7⋅137 \cdot 13?", it asks "which facts about multiplication follow from the rules alone, so that they hold for integers, for clock arithmetic, for matrices, for symmetries of a molecule, all at once?". That shift pays off in many places: symmetry (crystallography, chemistry, physics), cryptography (RSA and elliptic-curve systems are group theory in disguise), coding theory (error-correcting codes on every phone and disk are built over finite fields), and the classical question of solving polynomial equations, which Galois settled with groups. This series follows the standard senior undergraduate path of Dummit & Foote, Gallian, Artin and Fraleigh: groups, then rings and fields, then Galois theory. Post 00 lays the ground: the proof methods used throughout, sets and functions, equivalence relations, and the arithmetic of the integers up to modular arithmetic, the Chinese remainder theorem and a small but complete RSA example. Every later post uses Z\mathbb{Z} and Z/nZ\mathbb{Z}/n\mathbb{Z} as its first examples.

Series map: 00 Integers, Relations & Modular Arithmetic (this post) → 01 Groups & Subgroups → 02 Cosets, Lagrange & Quotient Groups → 03 Homomorphisms, Group Actions & Sylow → 04 Rings, Ideals & Fields → 05 Field Extensions & Galois Theory.


Learning Outcome

  • Read and write the four basic proof patterns: direct, contrapositive, contradiction, induction.
  • Decide whether a function is injective, surjective or bijective, and use the fact that bijections are exactly the invertible functions.
  • Prove that an equivalence relation on a set is the same thing as a partition of that set.
  • State and prove the division algorithm from the well-ordering principle.
  • Run the Euclidean algorithm and the extended Euclidean algorithm by hand, and prove Bézout's identity and Euclid's lemma.
  • Prove the fundamental theorem of arithmetic (existence and uniqueness).
  • Compute in Z/nZ\mathbb{Z}/n\mathbb{Z}, find inverses, and decide which classes are units.
  • Use Euler's φ\varphi function, Fermat's little theorem and Euler's theorem to reduce huge powers.
  • Solve simultaneous congruences with the Chinese remainder theorem.
  • Carry out a toy RSA key generation, encryption and decryption, and explain why decryption works.

Chapter 1 — The proof toolkit

Abstract algebra is a proof-based subject. Almost every statement is an implication "if PP then QQ", and there are four standard ways to prove one.

Terminology

  • Proposition / theorem / lemma / corollary — a proved statement; a lemma is a helper, a corollary follows quickly from a theorem.
  • Definition — fixes the meaning of a word. Definitions are "if and only if" even when written with "if".
  • Contrapositive of "P⇒QP \Rightarrow Q" is "not Q⇒Q \Rightarrow not PP". It is logically equivalent to the original.
  • Converse of "P⇒QP \Rightarrow Q" is "Q⇒PQ \Rightarrow P". It is a different statement and may be false.
  • Counterexample — one concrete case that shows a universal statement is false.

Direct proof

Assume PP, reason forward, reach QQ.

Claim. The sum of two odd integers is even.

Proof. Odd integers can be written 2a+12a+1 and 2b+12b+1 with a,b∈Za, b \in \mathbb{Z}. Their sum is 2a+2b+2=2(a+b+1)2a + 2b + 2 = 2(a+b+1), which is even. ■\blacksquare

Proof by contrapositive

Prove "not Q⇒Q \Rightarrow not PP" instead.

Claim. If n2n^2 is even, then nn is even.

Proof. Contrapositive: if nn is odd then n2n^2 is odd. Write n=2k+1n = 2k+1; then n2=4k2+4k+1=2(2k2+2k)+1n^2 = 4k^2 + 4k + 1 = 2(2k^2+2k) + 1, which is odd. ■\blacksquare

Proof by contradiction

Assume the statement is false and derive something impossible.

Claim. 2\sqrt{2} is irrational.

Proof. Suppose 2=p/q\sqrt{2} = p/q with integers p,qp, q, q≠0q \neq 0, and the fraction in lowest terms. Then p2=2q2p^2 = 2q^2, so p2p^2 is even, so pp is even by the previous claim. Write p=2mp = 2m: then 4m2=2q24m^2 = 2q^2, so q2=2m2q^2 = 2m^2 is even and qq is even. Both pp and qq are even, contradicting lowest terms. ■\blacksquare

Proof by induction

To prove a statement S(n)S(n) for all integers n≥n0n \geq n_0: prove S(n0)S(n_0) (the base case), then prove S(k)⇒S(k+1)S(k) \Rightarrow S(k+1) for every k≥n0k \geq n_0 (the inductive step). In strong induction the inductive step may assume S(n0),…,S(k)S(n_0), \dots, S(k) all at once.

Claim. For every n≥1n \geq 1, 1+3+5+⋯+(2n−1)=n21 + 3 + 5 + \dots + (2n-1) = n^2.

Proof. Base case n=1n=1: 1=121 = 1^2. Inductive step: if the sum of the first kk odd numbers is k2k^2, adding the next one gives k2+(2k+1)=(k+1)2k^2 + (2k+1) = (k+1)^2. ■\blacksquare

Watch out: proving the converse is not proving the statement. "If nn is even then n2n^2 is even" is true, but it does not prove "if n2n^2 is even then nn is even"; that needed its own proof above.


Chapter 2 — Sets, functions and equivalence relations

Terminology

  • N={0,1,2,… }\mathbb{N} = \{0, 1, 2, \dots\} (some books start at 1; this series includes 0), Z\mathbb{Z} the integers, Q\mathbb{Q} the rationals, R\mathbb{R} the reals, C\mathbb{C} the complex numbers.
  • A×B={(a,b):a∈A,b∈B}A \times B = \{(a, b) : a \in A, b \in B\} is the Cartesian product.
  • A function f:A→Bf : A \to B assigns to each a∈Aa \in A exactly one f(a)∈Bf(a) \in B. AA is the domain, BB the codomain, f(A)f(A) the image.
  • ff is injective (one-to-one) if f(a1)=f(a2)f(a_1) = f(a_2) implies a1=a2a_1 = a_2.
  • ff is surjective (onto) if every b∈Bb \in B equals f(a)f(a) for some aa.
  • ff is bijective if it is both. A bijection from a set to itself is a permutation of the set.
  • A relation on AA is a subset R⊆A×AR \subseteq A \times A; write a∼ba \sim b when (a,b)∈R(a, b) \in R.

Functions and inverses

Examples on Z\mathbb{Z}: f(x)=2xf(x) = 2x is injective but not surjective (odd numbers are missed). g(x)=⌊x/2⌋g(x) = \lfloor x/2 \rfloor is surjective but not injective (g(0)=g(1)=0g(0) = g(1) = 0). h(x)=x+5h(x) = x + 5 is bijective with inverse x↦x−5x \mapsto x - 5.

Proposition 2.1. A function f:A→Bf : A \to B has an inverse function g:B→Ag : B \to A (with g∘f=idAg \circ f = \mathrm{id}_A and f∘g=idBf \circ g = \mathrm{id}_B) if and only if ff is bijective.

Proof. If gg exists: f(a1)=f(a2)f(a_1) = f(a_2) gives a1=g(f(a1))=g(f(a2))=a2a_1 = g(f(a_1)) = g(f(a_2)) = a_2, so ff is injective; and any bb equals f(g(b))f(g(b)), so ff is surjective. Conversely, if ff is bijective, each bb has exactly one preimage; define g(b)g(b) to be it. Then both compositions are identities. ■\blacksquare

Proposition 2.2 (pigeonhole). If AA is a finite set and f:A→Af : A \to A is injective, then ff is bijective.

Proof. An injective ff sends the ∣A∣\lvert A\rvert elements of AA to ∣A∣\lvert A\rvert distinct elements of AA, so the image is all of AA. ■\blacksquare

This small fact drives the proofs of Fermat's little theorem below and of Cayley's theorem later in the series. It is false for infinite sets: x↦2xx \mapsto 2x on Z\mathbb{Z} is injective but not surjective.

Equivalence relations

A relation ∼\sim on AA is an equivalence relation if it is

  • reflexive: a∼aa \sim a for all aa;
  • symmetric: a∼ba \sim b implies b∼ab \sim a;
  • transitive: a∼ba \sim b and b∼cb \sim c imply a∼ca \sim c.

The equivalence class of aa is [a]={x∈A:x∼a}[a] = \{x \in A : x \sim a\}.

Examples: equality on any set; "same birthday" on people; "a−ba - b is divisible by nn" on Z\mathbb{Z} (Chapter 5); "same determinant" on 2×22 \times 2 matrices. Non-examples: ≤\leq on R\mathbb{R} is reflexive and transitive but not symmetric; "∣a−b∣≤1\lvert a - b\rvert \leq 1" on R\mathbb{R} is reflexive and symmetric but not transitive (0∼10 \sim 1, 1∼21 \sim 2, but 0≁20 \not\sim 2).

A partition of AA is a collection of non-empty subsets of AA such that every element of AA lies in exactly one of them.

Theorem 2.3 (equivalence relations = partitions). If ∼\sim is an equivalence relation on AA, its equivalence classes form a partition of AA. Conversely, every partition P\mathcal{P} of AA comes from exactly one equivalence relation: a∼ba \sim b if and only if aa and bb lie in the same block of P\mathcal{P}.

Proof. Each class is non-empty and every aa lies in a class, because a∈[a]a \in [a] by reflexivity. It remains to show that two classes are either equal or disjoint. Suppose c∈[a]∩[b]c \in [a] \cap [b], so c∼ac \sim a and c∼bc \sim b. Take any x∈[a]x \in [a]: then x∼ax \sim a, a∼ca \sim c (symmetry), c∼bc \sim b, so x∼bx \sim b by transitivity twice, and x∈[b]x \in [b]. Hence [a]⊆[b][a] \subseteq [b], and by the same argument [b]⊆[a][b] \subseteq [a]. So overlapping classes are equal.

Conversely, given a partition, "same block" is reflexive (every element is in a block), symmetric (obvious), and transitive (if a,ba, b share block PP and b,cb, c share block QQ, then b∈P∩Qb \in P \cap Q, so P=QP = Q because blocks are disjoint). Its classes are exactly the blocks. ■\blacksquare

Trick: to show two classes are equal it is enough to find one common element. This "one overlap means equal" step is used again for cosets in post 02, where it gives Lagrange's theorem almost for free.


Chapter 3 — Divisibility, gcd and the Euclidean algorithm

Terminology

  • aa divides bb, written a∣ba \mid b, if b=akb = ak for some integer kk. Every integer divides 00; 00 divides only 00.
  • A prime is an integer p≥2p \geq 2 whose only positive divisors are 11 and pp. An integer n≥2n \geq 2 that is not prime is composite.
  • The greatest common divisor gcd⁡(a,b)\gcd(a, b) of integers not both zero is the largest integer dividing both. Set gcd⁡(0,0)=0\gcd(0, 0) = 0.
  • aa and bb are coprime (relatively prime) if gcd⁡(a,b)=1\gcd(a, b) = 1.
  • Well-ordering principle: every non-empty set of non-negative integers has a least element. It is equivalent to induction and is taken as an axiom about N\mathbb{N}.

The division algorithm

Theorem 3.1 (division algorithm). For integers aa and bb with b>0b > 0 there are unique integers q,rq, r with

a=qb+r,0≤r<b.a = qb + r, \qquad 0 \leq r < b.

Proof. Existence: let S={a−kb:k∈Z, a−kb≥0}S = \{a - kb : k \in \mathbb{Z}, \ a - kb \geq 0\}. SS is non-empty (take k=−∣a∣k = -\lvert a\rvert; then a−kb=a+∣a∣b≥a+∣a∣≥0a - kb = a + \lvert a\rvert b \geq a + \lvert a\rvert \geq 0). By well-ordering SS has a least element r=a−qb≥0r = a - qb \geq 0. If r≥br \geq b, then r−b=a−(q+1)br - b = a - (q+1)b is a smaller element of SS, a contradiction. So 0≤r<b0 \leq r < b.

Uniqueness: if qb+r=q′b+r′qb + r = q'b + r' with both remainders in [0,b)[0, b), then b(q−q′)=r′−rb(q - q') = r' - r and ∣r′−r∣<b\lvert r' - r\rvert < b. The only multiple of bb strictly between −b-b and bb is 00, so r=r′r = r' and q=q′q = q'. ■\blacksquare

For negative aa the remainder is still non-negative: −17=(−4)⋅5+3-17 = (-4) \cdot 5 + 3, not (−3)⋅5−2(-3) \cdot 5 - 2.

Common pitfall: in many programming languages -17 % 5 returns -2 (C, Java, JavaScript) while Python returns 3. Mathematics always uses 0≤r<b0 \leq r < b.

The Euclidean algorithm

Lemma 3.2. If a=qb+ra = qb + r, then gcd⁡(a,b)=gcd⁡(b,r)\gcd(a, b) = \gcd(b, r).

Proof. Any common divisor of aa and bb divides r=a−qbr = a - qb; any common divisor of bb and rr divides a=qb+ra = qb + r. The two pairs have the same common divisors, so the same greatest one. ■\blacksquare

Repeating the division algorithm, the remainders strictly decrease and so reach 00; the last non-zero remainder is the gcd. For gcd⁡(240,46)\gcd(240, 46):

240=5⋅46+1046=4⋅10+610=1⋅6+46=1⋅4+24=2⋅2+0\begin{aligned} 240 &= 5 \cdot 46 + 10 \\ 46 &= 4 \cdot 10 + 6 \\ 10 &= 1 \cdot 6 + 4 \\ 6 &= 1 \cdot 4 + 2 \\ 4 &= 2 \cdot 2 + 0 \end{aligned}

So gcd⁡(240,46)=2\gcd(240, 46) = 2. The number of steps is small: it grows like the number of digits (Lamé's theorem bounds it by five times the number of decimal digits of the smaller number).

Bézout's identity and the extended algorithm

Theorem 3.3 (Bézout). For integers a,ba, b not both zero, there are integers x,yx, y with ax+by=gcd⁡(a,b)ax + by = \gcd(a, b). Moreover gcd⁡(a,b)\gcd(a, b) is the smallest positive integer of the form ax+byax + by.

Proof. Let S={ax+by:x,y∈Z}∩{1,2,3,… }S = \{ax + by : x, y \in \mathbb{Z}\} \cap \{1, 2, 3, \dots\}. It is non-empty (it contains a2+b2>0a^2 + b^2 > 0), so it has a least element d=ax0+by0d = ax_0 + by_0. Divide: a=qd+ra = qd + r with 0≤r<d0 \leq r < d. Then r=a−q(ax0+by0)=a(1−qx0)+b(−qy0)r = a - q(ax_0 + by_0) = a(1 - qx_0) + b(-qy_0) has the same form, so by minimality r=0r = 0 and d∣ad \mid a. Likewise d∣bd \mid b. Any common divisor cc of a,ba, b divides ax0+by0=dax_0 + by_0 = d, so c≤dc \leq d. Hence d=gcd⁡(a,b)d = \gcd(a, b). ■\blacksquare

The proof shows x,yx, y exist but does not find them. The extended Euclidean algorithm does: keep, next to every remainder rir_i, integers si,tis_i, t_i with ri=240si+46tir_i = 240 s_i + 46 t_i. Start with r0=240=240⋅1+46⋅0r_0 = 240 = 240 \cdot 1 + 46 \cdot 0 and r1=46=240⋅0+46⋅1r_1 = 46 = 240 \cdot 0 + 46 \cdot 1; each new row is "row two above minus qq times row above".

ii rir_i qiq_i sis_i tit_i check 240si+46ti240 s_i + 46 t_i
0 240 — 1 0 240
1 46 — 0 1 46
2 10 5 1 −5 240 − 230 = 10
3 6 4 −4 21 −960 + 966 = 6
4 4 1 5 −26 1200 − 1196 = 4
5 2 1 −9 47 −2160 + 2162 = 2
6 0 2 — — stop

So 2=240⋅(−9)+46⋅472 = 240 \cdot (-9) + 46 \cdot 47. The same answer comes from back-substitution, reading the divisions from the bottom up: 2=6−4=6−(10−6)=2⋅6−10=2(46−4⋅10)−10=2⋅46−9⋅10=2⋅46−9(240−5⋅46)=47⋅46−9⋅2402 = 6 - 4 = 6 - (10 - 6) = 2 \cdot 6 - 10 = 2(46 - 4 \cdot 10) - 10 = 2 \cdot 46 - 9 \cdot 10 = 2 \cdot 46 - 9(240 - 5 \cdot 46) = 47 \cdot 46 - 9 \cdot 240.

The extended Euclidean algorithm for 240 and 46 as a table of remainders, quotients and Bezout coefficients ending in 2 = 240 times -9 plus 46 times 47, next to the clock of Z/12Z with the units 1, 5, 7, 11 highlighted and zero divisors such as 3 times 4 equal to 0

Trick: the x,yx, y are not unique: (x+23k, y−120k)(x + 23k, \ y - 120k) works for every integer kk, because 240⋅23=46⋅120240 \cdot 23 = 46 \cdot 120. Add a check column like the one above; one wrong sign early ruins every later row.

Euclid's lemma

Theorem 3.4 (Euclid's lemma). If a∣bca \mid bc and gcd⁡(a,b)=1\gcd(a, b) = 1, then a∣ca \mid c. In particular, if a prime pp divides bcbc, then p∣bp \mid b or p∣cp \mid c.

Proof. By Bézout, ax+by=1ax + by = 1 for some x,yx, y. Multiply by cc: c=acx+bcyc = acx + bcy. The number aa divides acxacx and divides bcybcy (because a∣bca \mid bc), so a∣ca \mid c. For the prime case: if p∤bp \nmid b then gcd⁡(p,b)=1\gcd(p, b) = 1 (the only positive divisors of pp are 11 and pp), so p∣cp \mid c. ■\blacksquare

Watch out: the prime hypothesis matters. 6∣4⋅9=366 \mid 4 \cdot 9 = 36 but 6∤46 \nmid 4 and 6∤96 \nmid 9.


Chapter 4 — The fundamental theorem of arithmetic

Theorem 4.1 (fundamental theorem of arithmetic). Every integer n≥2n \geq 2 can be written as a product of primes n=p1p2⋯pkn = p_1 p_2 \cdots p_k, and this factorisation is unique up to the order of the factors.

Proof. Existence, by strong induction on nn. If nn is prime, it is its own factorisation. Otherwise n=abn = ab with 2≤a,b<n2 \leq a, b < n; by the induction hypothesis both aa and bb are products of primes, so nn is too.

Uniqueness, by induction on nn. Suppose n=p1⋯pk=q1⋯qln = p_1 \cdots p_k = q_1 \cdots q_l with all pi,qjp_i, q_j prime. Then p1p_1 divides q1⋯qlq_1 \cdots q_l, so by Euclid's lemma (applied repeatedly) p1∣qjp_1 \mid q_j for some jj. Since qjq_j is prime and p1≥2p_1 \geq 2, p1=qjp_1 = q_j. Reorder so that j=1j = 1 and cancel: p2⋯pk=q2⋯qlp_2 \cdots p_k = q_2 \cdots q_l is a smaller number (or both sides are empty products equal to 11), and by induction the remaining primes agree up to order. ■\blacksquare

Grouping equal primes gives the canonical form n=p1e1⋯prern = p_1^{e_1} \cdots p_r^{e_r} with p1<⋯<prp_1 < \dots < p_r. Examples: 360=23⋅32⋅5360 = 2^3 \cdot 3^2 \cdot 5, 1001=7⋅11⋅131001 = 7 \cdot 11 \cdot 13, 2026=2⋅10132026 = 2 \cdot 1013.

Corollary 4.2 (Euclid). There are infinitely many primes.

Proof. Given primes p1,…,pkp_1, \dots, p_k, the number N=p1⋯pk+1N = p_1 \cdots p_k + 1 has a prime factor pp by Theorem 4.1. If pp were some pip_i, then pp would divide N−p1⋯pk=1N - p_1 \cdots p_k = 1, which is impossible. So no finite list contains every prime. ■\blacksquare

Uniqueness is not automatic. In the set {a+b−5:a,b∈Z}\{a + b\sqrt{-5} : a, b \in \mathbb{Z}\}, 6=2⋅3=(1+−5)(1−−5)6 = 2 \cdot 3 = (1 + \sqrt{-5})(1 - \sqrt{-5}) gives two genuinely different factorisations into elements that cannot be split further. Explaining when unique factorisation holds is one of the main themes of ring theory (post 04).


Chapter 5 — Congruences and Z/nZ\mathbb{Z}/n\mathbb{Z}

Terminology

  • Fix an integer n≥1n \geq 1, the modulus. aa is congruent to bb modulo nn, written a≡b(modn)a \equiv b \pmod{n}, if n∣a−bn \mid a - b.
  • The class of aa is [a]n={a+kn:k∈Z}[a]_n = \{a + kn : k \in \mathbb{Z}\}, also written aˉ\bar{a} or just aa when the modulus is clear.
  • Z/nZ\mathbb{Z}/n\mathbb{Z} (also written Zn\mathbb{Z}_n) is the set of the nn classes [0],[1],…,[n−1][0], [1], \dots, [n-1].
  • A class [a][a] is a unit if there is [b][b] with [a][b]=[1][a][b] = [1]. The units form (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times, also written U(n)U(n).
  • A non-zero class [a][a] is a zero divisor if [a][b]=[0][a][b] = [0] for some non-zero [b][b].

Congruence mod nn is an equivalence relation: n∣0n \mid 0 (reflexive); n∣a−bn \mid a - b implies n∣b−an \mid b - a (symmetric); n∣a−bn \mid a - b and n∣b−cn \mid b - c imply n∣a−cn \mid a - c (transitive). By Theorem 2.3 its classes partition Z\mathbb{Z}, and by the division algorithm each class contains exactly one of 0,1,…,n−10, 1, \dots, n-1, so there are exactly nn classes.

Arithmetic on classes

Define [a]+[b]=[a+b][a] + [b] = [a + b] and [a]⋅[b]=[ab][a] \cdot [b] = [ab].

Proposition 5.1. These operations are well defined: the result does not depend on which representatives are chosen.

Proof. Suppose a≡a′a \equiv a' and b≡b′b \equiv b', say a′=a+kna' = a + kn and b′=b+lnb' = b + ln. Then a′+b′=a+b+(k+l)n≡a+ba' + b' = a + b + (k + l)n \equiv a + b and a′b′=ab+(al+bk+kln)n≡aba'b' = ab + (al + bk + kln)n \equiv ab. ■\blacksquare

"Well defined" is the central worry whenever an operation is defined on classes through representatives. The same check, done for cosets, is what forces the definition of a normal subgroup in post 02.

In practice: reduce early and often. For example 3100 mod 73^{100} \bmod 7: 36≡1(mod7)3^6 \equiv 1 \pmod 7 (checked below), and 100=6⋅16+4100 = 6 \cdot 16 + 4, so 3100=(36)16⋅34≡34=81≡4(mod7)3^{100} = (3^6)^{16} \cdot 3^4 \equiv 3^4 = 81 \equiv 4 \pmod 7.

Units and zero divisors

In Z/12Z\mathbb{Z}/12\mathbb{Z}: [3][4]=[12]=[0][3][4] = [12] = [0], so [3][3] and [4][4] are zero divisors. On the other hand [5][5]=[25]=[1][5][5] = [25] = [1], [7][7]=[49]=[1][7][7] = [49] = [1] and [11][11]=[121]=[1][11][11] = [121] = [1]. The units are exactly [1],[5],[7],[11][1], [5], [7], [11], the classes coprime to 1212, and each of them is its own inverse.

Theorem 5.2. [a][a] is a unit in Z/nZ\mathbb{Z}/n\mathbb{Z} if and only if gcd⁡(a,n)=1\gcd(a, n) = 1. If gcd⁡(a,n)=d>1\gcd(a, n) = d > 1 and n∤an \nmid a, then [a][a] is a zero divisor.

Proof. If gcd⁡(a,n)=1\gcd(a, n) = 1, Bézout gives ax+ny=1ax + ny = 1, so ax≡1ax \equiv 1 and [x][x] is the inverse. Conversely if ab≡1ab \equiv 1, then ab−1=knab - 1 = kn, so ab−kn=1ab - kn = 1 and every common divisor of aa and nn divides 11. For the last claim: a⋅(n/d)=(a/d)⋅n≡0a \cdot (n/d) = (a/d) \cdot n \equiv 0, and [n/d]≠[0][n/d] \neq [0] because 0<n/d<n0 < n/d < n. ■\blacksquare

Corollary 5.3. Z/nZ\mathbb{Z}/n\mathbb{Z} has every non-zero class invertible if and only if nn is prime.

Theorem 5.2 is also an algorithm: the inverse is the Bézout coefficient. To invert 1717 modulo 4343: 43=2⋅17+943 = 2 \cdot 17 + 9, 17=1⋅9+817 = 1 \cdot 9 + 8, 9=1⋅8+19 = 1 \cdot 8 + 1. Back-substitute: 1=9−8=9−(17−9)=2⋅9−17=2(43−2⋅17)−17=2⋅43−5⋅171 = 9 - 8 = 9 - (17 - 9) = 2 \cdot 9 - 17 = 2(43 - 2 \cdot 17) - 17 = 2 \cdot 43 - 5 \cdot 17. So 17−1≡−5≡38(mod43)17^{-1} \equiv -5 \equiv 38 \pmod{43}. Check: 17⋅38=646=15⋅43+117 \cdot 38 = 646 = 15 \cdot 43 + 1.

Linear congruences

Theorem 5.4. The congruence ax≡b(modn)ax \equiv b \pmod n has a solution if and only if d=gcd⁡(a,n)d = \gcd(a, n) divides bb. In that case it has exactly dd solutions modulo nn.

Proof sketch. A solution means ax−ny=bax - ny = b for some yy, and by Bézout the values of ax−nyax - ny are exactly the multiples of dd. If d∣bd \mid b, divide through: (a/d)x≡b/d(modn/d)(a/d)x \equiv b/d \pmod{n/d}, and a/da/d is a unit mod n/dn/d, so xx is unique mod n/dn/d. That single class mod n/dn/d splits into dd classes mod nn. ■\blacksquare

Example: 14x≡6(mod20)14x \equiv 6 \pmod{20}. Here gcd⁡(14,20)=2\gcd(14, 20) = 2 divides 66. Divide by 2: 7x≡3(mod10)7x \equiv 3 \pmod{10}. Since 7⋅3=21≡17 \cdot 3 = 21 \equiv 1, 7−1≡3(mod10)7^{-1} \equiv 3 \pmod{10}, so x≡9(mod10)x \equiv 9 \pmod{10}, giving x≡9x \equiv 9 or 19(mod20)19 \pmod{20}. Check: 14⋅9=126=6⋅20+614 \cdot 9 = 126 = 6 \cdot 20 + 6 and 14⋅19=266=13⋅20+614 \cdot 19 = 266 = 13 \cdot 20 + 6.

Common pitfall: you may not "divide both sides" of a congruence by a number that is not a unit. 2⋅3≡2⋅9(mod12)2 \cdot 3 \equiv 2 \cdot 9 \pmod{12}, but 3≢9(mod12)3 \not\equiv 9 \pmod{12}. Division by aa modulo nn is multiplication by a−1a^{-1}, which exists only when gcd⁡(a,n)=1\gcd(a, n) = 1; otherwise the modulus must be divided too, as above.


Chapter 6 — Euler's phi, Fermat and Euler

Euler's phi function

φ(n)\varphi(n) is the number of integers in {1,…,n}\{1, \dots, n\} coprime to nn; by Theorem 5.2 it is the number of units, φ(n)=∣(Z/nZ)×∣\varphi(n) = \lvert(\mathbb{Z}/n\mathbb{Z})^\times\rvert.

  • For a prime pp: φ(p)=p−1\varphi(p) = p - 1.
  • For a prime power: φ(pk)=pk−pk−1\varphi(p^k) = p^k - p^{k-1}, because the numbers in {1,…,pk}\{1, \dots, p^k\} not coprime to pkp^k are exactly the pk−1p^{k-1} multiples of pp.
  • Multiplicative: if gcd⁡(m,n)=1\gcd(m, n) = 1 then φ(mn)=φ(m)φ(n)\varphi(mn) = \varphi(m)\varphi(n). This follows from the Chinese remainder theorem (Chapter 7): aa is coprime to mnmn exactly when it is coprime to both mm and nn, and the CRT bijection matches such aa with pairs of units.

Together these give, for n=p1e1⋯prern = p_1^{e_1} \cdots p_r^{e_r},

φ(n)=n∏p∣n(1−1p).\varphi(n) = n \prod_{p \mid n} \left(1 - \frac{1}{p}\right).

Examples: φ(12)=12⋅12⋅23=4\varphi(12) = 12 \cdot \tfrac12 \cdot \tfrac23 = 4 (the units 1,5,7,111, 5, 7, 11); φ(36)=36⋅12⋅23=12\varphi(36) = 36 \cdot \tfrac12 \cdot \tfrac23 = 12; φ(100)=100⋅12⋅45=40\varphi(100) = 100 \cdot \tfrac12 \cdot \tfrac45 = 40; φ(35)=φ(5)φ(7)=4⋅6=24\varphi(35) = \varphi(5)\varphi(7) = 4 \cdot 6 = 24.

Fermat's little theorem

Theorem 6.1 (Fermat's little theorem). If pp is prime and p∤ap \nmid a, then ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p. Consequently ap≡a(modp)a^p \equiv a \pmod p for every integer aa.

Proof. Consider the map x↦axx \mapsto ax on the set R={[1],[2],…,[p−1]}R = \{[1], [2], \dots, [p-1]\} of non-zero classes mod pp. It lands in RR (a product of two units is a unit, so never [0][0]) and is injective, because ax≡ayax \equiv ay implies x≡yx \equiv y after multiplying by a−1a^{-1}. By the pigeonhole Proposition 2.2 it is a bijection, so it just reorders RR. Multiply all elements of RR both ways:

(a⋅1)(a⋅2)⋯(a⋅(p−1))≡1⋅2⋯(p−1)(modp),(a \cdot 1)(a \cdot 2) \cdots (a \cdot (p-1)) \equiv 1 \cdot 2 \cdots (p-1) \pmod p,

that is ap−1(p−1)!≡(p−1)!(modp)a^{p-1} (p-1)! \equiv (p-1)! \pmod p. Every factor of (p−1)!(p-1)! is a unit, so (p−1)!(p-1)! is a unit and can be cancelled: ap−1≡1a^{p-1} \equiv 1. For the second statement multiply by aa; if p∣ap \mid a both sides are 00. ■\blacksquare

Check with p=7p = 7, a=3a = 3: multiplying 1,2,3,4,5,61, 2, 3, 4, 5, 6 by 3 gives 3,6,2,5,1,43, 6, 2, 5, 1, 4 modulo 7, the same six classes in a new order, and 36=729=104⋅7+13^6 = 729 = 104 \cdot 7 + 1.

Euler's theorem

Theorem 6.2 (Euler). If gcd⁡(a,n)=1\gcd(a, n) = 1, then aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod n.

Proof. Repeat the proof above with the set UU of the φ(n)\varphi(n) units mod nn instead of RR: x↦axx \mapsto ax permutes UU, so aφ(n)∏u∈Uu≡∏u∈Uua^{\varphi(n)} \prod_{u \in U} u \equiv \prod_{u \in U} u, and the product of units is a unit, so it cancels. ■\blacksquare

Fermat is the case n=pn = p. Post 02 re-proves both in one line from Lagrange's theorem, because (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times is a group of order φ(n)\varphi(n) and the order of an element divides the order of the group.

Example: the last digit of 72227^{222}. φ(10)=4\varphi(10) = 4 and gcd⁡(7,10)=1\gcd(7, 10) = 1, so 74≡1(mod10)7^4 \equiv 1 \pmod{10}. Since 222=4⋅55+2222 = 4 \cdot 55 + 2, 7222≡72=49≡97^{222} \equiv 7^2 = 49 \equiv 9. The last digit is 9.

Watch out: Euler's theorem needs gcd⁡(a,n)=1\gcd(a, n) = 1. 2φ(4)=22=4≡0(mod4)2^{\varphi(4)} = 2^2 = 4 \equiv 0 \pmod 4, not 1. Also, φ(n)\varphi(n) is an exponent that always works, not always the smallest one: modulo 12, every unit already satisfies u2≡1u^2 \equiv 1 although φ(12)=4\varphi(12) = 4.


Chapter 7 — The Chinese remainder theorem

Theorem 7.1 (Chinese remainder theorem). Let n1,…,nkn_1, \dots, n_k be pairwise coprime positive integers and N=n1⋯nkN = n_1 \cdots n_k. For any integers a1,…,aka_1, \dots, a_k the system

x≡a1(modn1),…,x≡ak(modnk)x \equiv a_1 \pmod{n_1}, \quad \dots, \quad x \equiv a_k \pmod{n_k}

has a solution, and any two solutions are congruent modulo NN.

Proof. Existence: put Ni=N/niN_i = N / n_i. Since nin_i is coprime to every other njn_j, it is coprime to NiN_i, so there is MiM_i with NiMi≡1(modni)N_i M_i \equiv 1 \pmod{n_i}. Let x=∑iaiNiMix = \sum_i a_i N_i M_i. Modulo njn_j, every term with i≠ji \neq j vanishes (because nj∣Nin_j \mid N_i), and the jj-th term is aj⋅1a_j \cdot 1. Uniqueness: if x,x′x, x' both work, each nin_i divides x−x′x - x'; the nin_i are pairwise coprime, so (by Euclid's lemma, repeatedly) their product NN divides x−x′x - x'. ■\blacksquare

Worked example (Sunzi's classic puzzle). Find xx with x≡2(mod3)x \equiv 2 \pmod 3, x≡3(mod5)x \equiv 3 \pmod 5, x≡2(mod7)x \equiv 2 \pmod 7. Here N=105N = 105.

ii nin_i aia_i Ni=N/niN_i = N/n_i Ni mod niN_i \bmod n_i MiM_i aiNiMia_i N_i M_i
1 3 2 35 2 2 140
2 5 3 21 1 1 63
3 7 2 15 1 1 30

Sum: 140+63+30=233≡23(mod105)140 + 63 + 30 = 233 \equiv 23 \pmod{105}. Check: 23=7⋅3+223 = 7 \cdot 3 + 2, 23=4⋅5+323 = 4 \cdot 5 + 3, 23=3⋅7+223 = 3 \cdot 7 + 2.

In structural language, the theorem says that the map Z/NZ→Z/n1Z×⋯×Z/nkZ\mathbb{Z}/N\mathbb{Z} \to \mathbb{Z}/n_1\mathbb{Z} \times \dots \times \mathbb{Z}/n_k\mathbb{Z}, [x]↦([x]n1,…,[x]nk)[x] \mapsto ([x]_{n_1}, \dots, [x]_{n_k}), is a bijection that respects addition and multiplication. Both sides have NN elements, so it is enough to know the map is injective, which is the uniqueness part. Post 01 meets the additive version as "Z/6Z\mathbb{Z}/6\mathbb{Z} is the same group as Z/2Z×Z/3Z\mathbb{Z}/2\mathbb{Z} \times \mathbb{Z}/3\mathbb{Z}", and post 04 the ring version.

Common pitfall: the moduli must be pairwise coprime. The system x≡0(mod4)x \equiv 0 \pmod 4, x≡1(mod6)x \equiv 1 \pmod 6 has no solution: the first says xx is even, the second says xx is odd.


Chapter 8 — A toy RSA

RSA (Rivest, Shamir and Adleman, 1978) is Euler's theorem put to work. The numbers below are tiny so that every step can be checked by hand; real keys use primes of about 1024 bits or more and a padding scheme, and textbook RSA as shown here is not secure.

Key generation.

  1. Pick primes p=11p = 11, q=17q = 17. The modulus is n=pq=187n = pq = 187.
  2. φ(n)=(p−1)(q−1)=10⋅16=160\varphi(n) = (p-1)(q-1) = 10 \cdot 16 = 160.
  3. Pick a public exponent ee coprime to 160: e=7e = 7.
  4. The private exponent is d=e−1 mod φ(n)d = e^{-1} \bmod \varphi(n): since 7⋅23=161=160+17 \cdot 23 = 161 = 160 + 1, d=23d = 23.

Public key (n,e)=(187,7)(n, e) = (187, 7); private key d=23d = 23.

Encryption of the message m=88m = 88 (any integer with 0≤m<n0 \leq m < n): c=me mod nc = m^e \bmod n, computed by repeated squaring so that no number exceeds 1862186^2:

882=7744≡77(mod187)884≡772=5929≡132887=884⋅882⋅88≡132⋅77⋅88≡66⋅88=5808≡11\begin{aligned} 88^2 &= 7744 \equiv 77 \pmod{187} \\ 88^4 &\equiv 77^2 = 5929 \equiv 132 \\ 88^7 &= 88^4 \cdot 88^2 \cdot 88 \equiv 132 \cdot 77 \cdot 88 \equiv 66 \cdot 88 = 5808 \equiv 11 \end{aligned}

So the ciphertext is c=11c = 11.

Decryption: cd=1123 mod 187c^d = 11^{23} \bmod 187. Write 23=16+4+2+123 = 16 + 4 + 2 + 1 and square repeatedly: 112=12111^2 = 121, 114≡1212=14641≡5511^4 \equiv 121^2 = 14641 \equiv 55, 118≡552=3025≡3311^8 \equiv 55^2 = 3025 \equiv 33, 1116≡332=1089≡15411^{16} \equiv 33^2 = 1089 \equiv 154. Then

1123≡154⋅55⋅121⋅11≡55⋅121⋅11≡110⋅11=1210≡88(mod187).11^{23} \equiv 154 \cdot 55 \cdot 121 \cdot 11 \equiv 55 \cdot 121 \cdot 11 \equiv 110 \cdot 11 = 1210 \equiv 88 \pmod{187}.

The original message comes back.

Why it works. ed=1+kφ(n)ed = 1 + k\varphi(n) for some k≥0k \geq 0. If gcd⁡(m,n)=1\gcd(m, n) = 1, Euler gives med=m⋅(mφ(n))k≡m(modn)m^{ed} = m \cdot (m^{\varphi(n)})^k \equiv m \pmod n. (If mm shares a factor with nn, the result still holds: check it modulo pp and modulo qq separately with Fermat, then combine with the CRT.)

Why it is believed hard to break. Anyone who knows φ(n)\varphi(n) can compute dd with the extended Euclidean algorithm, and φ(n)\varphi(n) is easy from pp and qq. So the security rests on the difficulty of factoring nn; no fast classical factoring algorithm is known.


Practice Exercises

1. Prove by induction that 6∣n3−n6 \mid n^3 - n for every integer n≥0n \geq 0.

Solution

Base: 03−0=00^3 - 0 = 0. Step: (k+1)3−(k+1)=(k3−k)+3k2+3k=(k3−k)+3k(k+1)(k+1)^3 - (k+1) = (k^3 - k) + 3k^2 + 3k = (k^3 - k) + 3k(k+1). The first term is divisible by 6 by hypothesis; k(k+1)k(k+1) is a product of consecutive integers, hence even, so 3k(k+1)3k(k+1) is divisible by 6. (A direct proof also works: n3−n=(n−1)n(n+1)n^3 - n = (n-1)n(n+1) is a product of three consecutive integers, so it is divisible by 2 and by 3.)

2. On R2\mathbb{R}^2 define (x1,y1)∼(x2,y2)(x_1, y_1) \sim (x_2, y_2) if x12+y12=x22+y22x_1^2 + y_1^2 = x_2^2 + y_2^2. Show this is an equivalence relation and describe the partition.

Solution

It is "f(p1)=f(p2)f(p_1) = f(p_2)" for the function f(x,y)=x2+y2f(x, y) = x^2 + y^2, and any relation of that form inherits reflexivity, symmetry and transitivity from equality. The classes are the circles centred at the origin, plus the single point (0,0)(0,0).

3. Use the extended Euclidean algorithm to find gcd⁡(252,198)\gcd(252, 198) and integers x,yx, y with 252x+198y=gcd⁡(252,198)252x + 198y = \gcd(252, 198).

Solution

252=1⋅198+54252 = 1 \cdot 198 + 54, 198=3⋅54+36198 = 3 \cdot 54 + 36, 54=1⋅36+1854 = 1 \cdot 36 + 18, 36=2⋅1836 = 2 \cdot 18. So the gcd is 18. Back-substitute: 18=54−36=54−(198−3⋅54)=4⋅54−198=4(252−198)−198=4⋅252−5⋅19818 = 54 - 36 = 54 - (198 - 3 \cdot 54) = 4 \cdot 54 - 198 = 4(252 - 198) - 198 = 4 \cdot 252 - 5 \cdot 198. Check: 1008−990=181008 - 990 = 18.

4. Find all solutions of 14x≡6(mod20)14x \equiv 6 \pmod{20} by the method of Theorem 5.4, and explain why 14x≡5(mod20)14x \equiv 5 \pmod{20} has none.

Solution

As in Chapter 5: x≡9x \equiv 9 or 19(mod20)19 \pmod{20}. For the second congruence, gcd⁡(14,20)=2\gcd(14, 20) = 2 does not divide 5: the left side 14x−20y14x - 20y is always even, the right side is odd.

5. Compute 21000 mod 132^{1000} \bmod 13 and the last two digits of 320263^{2026}.

Solution

By Fermat 212≡1(mod13)2^{12} \equiv 1 \pmod{13}; 1000=12⋅83+41000 = 12 \cdot 83 + 4, so 21000≡24=16≡32^{1000} \equiv 2^4 = 16 \equiv 3. For the last two digits work mod 100: φ(100)=40\varphi(100) = 40 and gcd⁡(3,100)=1\gcd(3, 100) = 1, so 340≡13^{40} \equiv 1; 2026=40⋅50+262026 = 40 \cdot 50 + 26, so 32026≡3263^{2026} \equiv 3^{26}. Now 35=243≡433^5 = 243 \equiv 43, 310≡432=1849≡493^{10} \equiv 43^2 = 1849 \equiv 49, 320≡492=2401≡13^{20} \equiv 49^2 = 2401 \equiv 1. (The order of 3 mod 100 is actually 20, a divisor of 40.) So 326≡36=729≡293^{26} \equiv 3^{6} = 729 \equiv 29. The last two digits are 29.

6. Solve x≡3(mod4)x \equiv 3 \pmod 4, x≡4(mod9)x \equiv 4 \pmod 9.

Solution

N=36N = 36. N1=9≡1(mod4)N_1 = 9 \equiv 1 \pmod 4, so M1=1M_1 = 1; N2=4N_2 = 4 and 4⋅7=28≡1(mod9)4 \cdot 7 = 28 \equiv 1 \pmod 9, so M2=7M_2 = 7. Then x=3⋅9⋅1+4⋅4⋅7=27+112=139≡31(mod36)x = 3 \cdot 9 \cdot 1 + 4 \cdot 4 \cdot 7 = 27 + 112 = 139 \equiv 31 \pmod{36}. Check: 31=7⋅4+331 = 7 \cdot 4 + 3 and 31=3⋅9+431 = 3 \cdot 9 + 4.

7. With p=5p = 5, q=11q = 11 and e=3e = 3, find nn, φ(n)\varphi(n) and dd; encrypt m=7m = 7 and decrypt the result.

Solution

n=55n = 55, φ(n)=4⋅10=40\varphi(n) = 4 \cdot 10 = 40, d=27d = 27 because 3⋅27=81=2⋅40+13 \cdot 27 = 81 = 2 \cdot 40 + 1. Encrypt: 73=343=6⋅55+137^3 = 343 = 6 \cdot 55 + 13, so c=13c = 13. Decrypt: 132=169≡413^2 = 169 \equiv 4, 134≡1613^4 \equiv 16, 138≡256≡3613^8 \equiv 256 \equiv 36, 1316≡362=1296≡3113^{16} \equiv 36^2 = 1296 \equiv 31. With 27=16+8+2+127 = 16 + 8 + 2 + 1: 31⋅36=1116≡1631 \cdot 36 = 1116 \equiv 16, 16⋅4=64≡916 \cdot 4 = 64 \equiv 9, 9⋅13=117≡79 \cdot 13 = 117 \equiv 7. The message 7 comes back.


Cheat-sheet

Idea Statement or method
Equivalence relation reflexive, symmetric, transitive; classes partition the set
Division algorithm a=qb+ra = qb + r, 0≤r<b0 \leq r < b, unique
Euclidean algorithm gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a, b) = \gcd(b, a \bmod b); last non-zero remainder
Bézout ax+by=gcd⁡(a,b)ax + by = \gcd(a, b); gcd is the least positive such value
Extended Euclid new row = row two above minus qq times row above
Euclid's lemma p∣bc⇒p∣bp \mid bc \Rightarrow p \mid b or p∣cp \mid c
FTA unique factorisation into primes, up to order
Z/nZ\mathbb{Z}/n\mathbb{Z} nn classes; ++ and ⋅\cdot well defined
Unit test [a][a] invertible iff gcd⁡(a,n)=1\gcd(a, n) = 1; inverse from Bézout
ax≡bax \equiv b solvable iff gcd⁡(a,n)∣b\gcd(a,n) \mid b; then gcd⁡(a,n)\gcd(a,n) solutions
Euler phi φ(n)=n∏(1−1/p)\varphi(n) = n \prod (1 - 1/p) over primes p∣np \mid n
Fermat ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p if p∤ap \nmid a
Euler aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod n if gcd⁡(a,n)=1\gcd(a, n) = 1
CRT pairwise coprime moduli: unique solution mod N=∏niN = \prod n_i
RSA n=pqn = pq, ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)}, c=mec = m^e, m=cdm = c^d mod nn

What's next

Post 01 takes the pattern seen here (a set, one operation, an identity, inverses) and turns it into the definition of a group. Z\mathbb{Z} under addition, Z/nZ\mathbb{Z}/n\mathbb{Z} under addition and (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times under multiplication become the first examples, joined by permutations, symmetries of polygons, invertible matrices and the quaternions. The division algorithm reappears in the proof that every subgroup of a cyclic group is cyclic, and gcd⁡\gcd returns in the formula n/gcd⁡(k,n)n / \gcd(k, n) for the order of kk in Z/nZ\mathbb{Z}/n\mathbb{Z}.


References

  • David S. Dummit and Richard M. Foote, Abstract Algebra, 3rd edition, Wiley, 2004 — Chapter 0 (preliminaries: relations, integers, Z/nZ\mathbb{Z}/n\mathbb{Z}).
  • Joseph A. Gallian, Contemporary Abstract Algebra, 10th edition, CRC Press, 2021 — Chapter 0 (preliminaries, including the RSA-style applications).
  • Michael Artin, Algebra, 2nd edition, Pearson, 2011.
  • John B. Fraleigh, A First Course in Abstract Algebra, 7th edition, Addison-Wesley, 2003 — Section 0 (sets and relations).
  • Ivan Niven, Herbert S. Zuckerman and Hugh L. Montgomery, An Introduction to the Theory of Numbers, 5th edition, Wiley, 1991 — divisibility, congruences, the CRT.
  • Thomas W. Judson, Abstract Algebra: Theory and Applications (open textbook), judsonbooks.org — chapters on the integers and on RSA.
  • MIT OpenCourseWare, 18.701 Algebra I (Fall 2010) — lecture notes and problem sets following Artin.
  • R. L. Rivest, A. Shamir and L. Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM 21(2), 1978, pp. 120–126.

Note: this post is in progress. Planned additions: a proof that well-ordering and induction are equivalent, the CRT proof of multiplicativity of φ\varphi written out in full, Wilson's theorem, and a short section on fast modular exponentiation cost (number of multiplications versus bit length).