Modular Arithmetic and Group Theory


Modular Arithmetic and Group Theory

Simon
Last time, modular arithmetic led us to a practical question: when does a number have a multiplicative inverse modulo n? The key test is the greatest common divisor. An element a has an inverse modulo n exactly when gcd(a,n)=1.

Corey
And that connects to the extended Euclidean algorithm. If gcd(a,n)=1, Bézout’s identity gives integers s and t such that sa+tn=1. Reducing modulo n leaves sa congruent to 1, so s is an inverse of a. If the gcd is greater than 1, an inverse cannot exist.

Simon
That’s the bridge to group theory. A group is a set of elements together with one operation—often written with a star—that satisfies four rules: closure, associativity, an identity element, and an inverse for every element.

Corey
Closure means operating on two elements in the set gives another element in the set. Associativity says the placement of parentheses doesn’t change the result: a star b, then star c, agrees with a star, b star c.

Simon
The identity is an element e that leaves every element unchanged on either side. And an inverse for a takes you back to the identity, whether you apply it on the left or the right. If the operation also commutes—so a star b equals b star a—the group is called abelian.

Corey
We’ve already met familiar examples. The integers under addition form an infinite abelian group: sums remain integers, zero is the identity, and the inverse of an integer is its negative.

Simon
But the integers under multiplication do not form a group. Zero has no multiplicative inverse, and neither does 2 within the integers, because its inverse would be one-half, which isn’t an integer. So the set alone isn’t enough; the operation matters.

Corey
The nonzero rational numbers under multiplication do form a group. Products stay nonzero and rational, 1 is the identity, and every element has a reciprocal that is still a nonzero rational number.

Simon
A finite example is the residues modulo n under addition. For instance, modulo 2, the residues are 0 and 1. Adding them modulo 2 stays in that set, zero is the identity, and each element has an additive inverse.

Corey
Now consider multiplication modulo n. If n is prime, the nonzero residues form a group: multiplication stays among the nonzero residues, 1 is the identity, and every nonzero residue has an inverse.

Simon
The inverse property is the important one there. The gcd test says every nonzero residue has an inverse when n is prime. Conversely, if n is composite, there’s a nonzero residue sharing a factor with n, and that residue has no inverse. So the nonzero residues under multiplication form a group if and only if n is prime.

Corey
For composite n, we can still find a group by keeping only the residues that are relatively prime to n. We call that set Z-n-star, or the units modulo n, and use multiplication modulo n. Those are exactly the elements that have multiplicative inverses.

Simon
That gives us the right language for counting. The order of a finite group means simply its number of elements. For the nonzero residues modulo a prime p, the order is p minus 1.

Corey
And for n equal to p times q, where p and q are distinct primes, the units modulo n have order (p minus 1) times (q minus 1). To count them, start with the pq minus 1 nonzero residues, then exclude the multiples of p and the multiples of q.

Simon
There are q minus 1 nonzero multiples of p among those residues, and p minus 1 multiples of q. No nonzero residue below pq is a multiple of both. Subtracting those two counts gives pq minus 1 minus (q minus 1) minus (p minus 1), which simplifies to (p minus 1)(q minus 1).

Corey
That count will matter later in cryptography, especially for RSA. But first, we need another definition: a subgroup is a subset of a group that is itself a group using the same operation.

Simon
That means more than just having elements inside the bigger group. If a and b are in the subgroup, their product must stay in the subgroup; and if a is in it, its inverse must stay there too. The subgroup has to be closed under the operation and inverses, as well as having the other group properties.

Corey
Here’s a small example. In the nonzero residues modulo 7 under multiplication, the set containing 1, 2, and 4 is a subgroup. They’re the powers of 2: 2, then 2 squared is 4, then 2 cubed is 1 modulo 7.

Simon
That powers pattern explains the closure: multiplying powers of 2 adds their exponents, and the results cycle back through 1, 2, and 4. The subgroup has order 3, while the whole group has order 6.

Corey
That illustrates Lagrange’s theorem: in any finite group G, the order of a subgroup H divides the order of G. So a group of order 6 cannot contain a subgroup of order 4, for example.

Simon
The proof uses cosets. For an element x in G, the left coset xH is the set of all products x times h, as h ranges over H. Each coset is a translated copy of H.

Corey
Why does each copy have the same size as H? If two choices h1 and h2 gave the same product, xh1 equals xh2, we could multiply on the left by x’s inverse and conclude h1 equals h2. So distinct elements of H give distinct elements of xH.

Simon
Next, choose cosets by repeatedly picking an element not covered yet and using it as a new representative. The resulting cosets cannot overlap. If xi h1 equals xj h2, then multiplying on the right by h2’s inverse gives xj equals xi times h1 h2-inverse.

Corey
And h1 h2-inverse is in H, because H is closed under inverses and multiplication. That means xj was already in the earlier coset xi H, contradicting the rule that we chose it uncovered. So the cosets are disjoint.

Simon
Eventually they cover all of G, and each has exactly as many elements as H. If there are k cosets, then the size of G is k times the size of H. That’s why the order of H must divide the order of G.

Corey
Now for a major application: Fermat’s little theorem. If p is prime and a is not divisible by p, then a to the power p minus 1 is congruent to 1 modulo p.

Simon
Here’s the group-theoretic proof. Look at successive powers of a modulo p. Some power must return to 1: there are only finitely many nonzero residues, so the powers eventually repeat. Since a has an inverse modulo p, a repetition lets us cancel the earlier powers and obtain a positive power equal to 1.

Corey
Let k be the smallest positive exponent with a to the k congruent to 1. The powers of a form a subgroup, and its order is k: the powers cycle back to the identity for the first time after k steps.

Simon
The whole group of nonzero residues modulo p has order p minus 1. By Lagrange’s theorem, k divides p minus 1. So p minus 1 is some multiple of k, and a to the power p minus 1 is a power of a to the k—which is 1.

Corey
There’s a useful bonus: since a times a to the power p minus 2 is congruent to 1 modulo p, the inverse of a is a to the power p minus 2. That gives a formula for the inverse, alongside the method using the extended Euclidean algorithm.

Simon
The lecture also gives a combinatorial way to see Fermat’s theorem in a specific case: a equals 2 and p equals 5. Count strings of length 5 using two bead colors. There are 2 to the fifth, or 32, strings.

Corey
Now connect the ends of each string to make a necklace, where rotations count as the same necklace. Because 5 is prime, every nonconstant necklace comes from 5 different strings—one for each rotation. The only necklaces that don’t have five distinct rotations are the all-red and all-blue ones.

Simon
So the 32 strings consist of two constant strings plus groups of five nonconstant strings. That makes 32 minus 2 divisible by 5. More generally, the same counting idea gives that p divides a to the p minus a, which is equivalent to Fermat’s little theorem after using that a is nonzero modulo p.

Corey
That example shows how one result can have different explanations: group theory gives a structural proof, while counting necklaces gives a combinatorial one. Each viewpoint can reveal something different about the mathematics.

Simon
There’s a related result for a composite modulus. If m equals p times q for distinct primes and gcd(a,m)=1, then a to the power (p minus 1)(q minus 1) is congruent to 1 modulo m. This is Euler’s theorem.

Corey
The proof follows the same pattern. The powers of a form a subgroup of the units modulo m. If k is the first positive exponent that brings a back to 1, that subgroup has order k, so Lagrange says k divides the order of the whole unit group.

Simon
And we counted that group’s order as (p minus 1)(q minus 1). Therefore that exponent is a multiple of k, and raising a to it gives 1 modulo m. The difference from Fermat’s theorem comes from the size of the group of invertible residues.

Corey
That’s why the earlier count is important. Euler’s theorem is a key idea behind RSA encryption, which the course will explore later. Group theory makes the exponent in the theorem less mysterious: it comes from the order of the relevant group.

Simon
One final structure for today is a field. A field has addition and multiplication. Under addition, all its elements form an abelian group, with identity 0; under multiplication, the nonzero elements form an abelian group, with identity 1.

Corey
And the two operations connect through distributivity: a times the quantity b plus c equals a times b plus a times c. The rational numbers are a familiar example of a field, and finite fields will be useful in cryptography.

Simon
A theorem about fields says that a nonzero polynomial of degree d has at most d roots in the field. A root is a value from the field that makes the polynomial evaluate to zero. This isn’t just a fact about real-number polynomials; it holds over any field.

Corey
That root bound will matter in secret sharing. The basic idea is to encode a secret as the constant coefficient of a polynomial over a finite field, then give participants evaluations of that polynomial at different points.

Simon
With enough points, they can reconstruct the polynomial and recover the secret; with fewer than the required number, they cannot. So the ideas from groups, modular arithmetic, and fields are all setting up tools for later cryptography.

Ask anything
We've read this whole study set, so questions about it get the best answers.