Path: blob/main/foundations/01-modular-arithmetic-groups/sage/01d-cyclic-groups-generators.ipynb
483 views
Cyclic Groups and Generators
Module 01d | Modular Arithmetic and Groups
Take one element, multiply it by itself over and over. Sometimes you get the entire group back. That's the idea behind most of modern cryptography.
Where we left off. In 01c we verified that is a group: you can multiply any two elements and get another element, there's an identity (1), and every element has an inverse. Now let's see what happens when we take one element and keep multiplying it by itself.
Objectives
By the end of this notebook you will be able to:
Explain why repeated multiplication in a finite group must cycle back to 1
Compute the order of an element (the length of its cycle)
Determine whether an element is a generator (its cycle is the whole group)
Define cyclic group and identify examples (and non-examples)
Count generators using Euler's totient function
Connect generators to the discrete logarithm problem
One Element, Repeated Multiplication
Pick the element 3 in . Compute and watch what happens.
After 6 steps we're back to 1, and the cycle would repeat: , , and so on.
Before hitting 1, the powers visited , which is the ENTIRE group . Every element appeared exactly once.
Now try element 2:
Element 2 hit 1 after only 3 steps: . Then the cycle repeats: , , . It only ever touches , never reaching 3, 5, or 6.
Why must it cycle at all? The group has 6 elements. Each multiplication gives another element in the group (closure!). After 6 multiplications, you've produced 6 elements but there are only 6 possibilities. By the pigeonhole principle, some value must repeat. Once any value repeats, the whole pattern cycles. And it always cycles back to 1 (we'll see why shortly).
Every Element Traces a Cycle
Let's compute the power cycle for every element in .
Some elements have long cycles (3 and 5 reach all 6 elements), others have short ones (6 cycles in just 2 steps). Let's visualize these cycles.
Order = Cycle Length
The length of an element's cycle has a name: its order.
Definition. The order of , written , is the smallest positive integer such that .
In other words, the order is how many times you need to multiply by itself before getting back to the identity. SageMath computes this with .multiplicative_order().
Why must the order divide the group size? Here's the intuition.
We know for every in a group of size 6 (this is a consequence of Lagrange's theorem, which we'll prove in 01e). If , then the powers cycle with period . For to equal 1, the period must divide 6. If were 4, then and (unless too, which means was really 2 or 1, not 4).
Checkpoint. Predict the possible orders in before computing. The group has elements. What numbers divide 10?
Generators: Elements That Reach Everything
An element whose cycle covers the entire group has a special name.
Definition. An element is a generator of if . Equivalently, .
If is a generator, then every element in the group can be written as for some unique . This is like having a complete address system: every group element has a unique "exponent address."
Cyclic Groups
A group that has at least one generator is called a cyclic group. The name comes from the picture we just saw: a generator's powers cycle through every element in the group and then loop back to 1.
is cyclic because 3 is a generator (so is 5). One generator is enough for the group to earn the name "cyclic," even though most elements are not generators.
This is a big structural claim. It says the entire group can be "unrolled" from a single element. Every element is just a power of the generator. The group has no hidden corners, no elements that live outside some generator's reach.
Cyclic groups are everywhere
In fact, you already know the most natural cyclic group: , the integers mod under addition. The element 1 generates everything, because ( times) gives you , and that hits every element .
Not all groups are cyclic
Here's a natural question: is every group cyclic? No. Some groups have no generator at all. No single element can reach everything.
Consider , the units mod 15. This group has elements. If it were cyclic, some element would have order 8. Let's check.
Why cyclic matters for cryptography
Cryptography needs cyclic groups. Here's why:
If the group is cyclic with generator , every element has a unique exponent: . This exponent is the discrete logarithm, and finding it is the hard problem that secures Diffie-Hellman and related schemes.
If the group is not cyclic, there's no single generator, so you can't set up a clean DLP. The algebraic structure is messier and harder to build protocols on.
That's why for prime is the classic choice: it's always cyclic (a theorem we'll take on faith for now). Elliptic curve groups used in practice are also cyclic.
Key fact. is cyclic if and only if , or for an odd prime . In particular, it's cyclic for every prime , which is the case we care about most. We'll explore non-cyclic unit groups more in 01e.
The Discrete Logarithm Problem
If generates , and someone gives you , finding is called the discrete logarithm problem (DLP). It's called a "logarithm" because it undoes exponentiation, just like undoes for real numbers.
For our tiny group, brute force works fine:
Why is the DLP hard? Computing is fast (you can use repeated squaring, which takes roughly steps). But going backward, finding from , has no known shortcut for general groups. Exponentiation in a finite group scrambles the relationship between and so thoroughly that the only known approach for generic groups is to try exponents one by one.
This asymmetry (easy forward, hard backward) is the foundation of most public-key cryptography.
Counting Generators
Not every element is a generator. How many generators does have?
An element is a generator when . It turns out the count is exactly , where is Euler's totient function.
Why? If is one generator, then is also a generator exactly when (because ). The number of values with is, by definition, .
Common mistake. "The order of an element is its numerical value." No! In , element 2 has order 3, and element 3 has order 6. The order is the length of the cycle when you keep multiplying. It's a structural property, not a numerical one.
A Taste of Diffie-Hellman
Here's a sketch of how generators power real cryptography. Alice and Bob agree publicly on a prime and a generator of .
Exercises
Exercise 1 (Worked)
List all powers of 2 in . Determine . Is 2 a generator?
Exercise 2 (Guided)
Find all generators of . Verify the count matches .
Exercise 3 (Independent)
In , how many generators exist? Find them all. Then pick one generator and verify that every element in can be written as for exactly one . What is ?
Summary
| Concept | Key idea |
|---|---|
| Power cycle | Repeated multiplication must eventually return to 1 |
| Order | = length of the cycle = smallest with |
| Divisibility | always divides $ |
| Generator | is a generator iff $\text{ord}(g) = |
| Cyclic group | A group with at least one generator. All of are cyclic. |
| Non-cyclic | Some groups (like ) have no generator at all |
| Generator count | Exactly $\varphi( |
| DLP | Finding from is the discrete logarithm problem, computationally hard for large groups |
The punchline: a cyclic group can be "unrolled" from a single generator. Every element gets a unique exponent "address." Computing addresses is easy (multiply), but reversing them is hard (discrete log). That asymmetry is the foundation of Diffie-Hellman, ElGamal, and DSA.
Next: Subgroups and Lagrange's Theorem. Non-generators create smaller groups inside the big one, and their sizes are brutally constrained by divisibility.