blog

Proving RSA Encryption: An Application of Group Theory (Part 2: Fermat's Little Theorem and Ring Theory)

This post is going to be a little heavy on the group theory— I’m going to try to build everything from the ground up but having a prior understanding of the basics of groups will be very useful. Let’s start by stating an important theorem:

Theorem (Fermat’s Little Theorem): Let aZa \in \mathbb{Z}, pp a prime. If pp doesn’t divide aa, then pp divides ap11a^{p-1} - 1, that is,

a{p1}1({mod}p).a^\{p-1\} \equiv 1 \, (\text\{mod\} \, p).

Those with a background in number theory may be more familiar with this equivalent statement of the theorem: If aZa \in \mathbb{Z}, then apa(modp)a^p \equiv a \, (\text{mod} \, p) for pp a prime.

Proof: I have discovered a truly remarkable proof that is too large to be contained in the margins of this post.

Just kidding. Before we prove Fermat’s Little Theorem, let’s talk about groups and fields. Here’s how groups are defined (I’m going to let addition denote an arbitrary binary operation):

Definition: A group G,+\langle G,+ \rangle is a set GG closed under addition such that- G_1\mathscr{G}\_1 (Associativity): For all a,b,cG,a, b, c \in G,

(a+b)+c=a+(b+c)(a+b)+c = a+(b+c)
  • G_2  \mathscr{G}\_2 (Identity): There exists an element 0G0 \in G such that for all aGa \in G, 0+a=a+0=a.0+a=a+0=a.
  • G_3  \mathscr{G}\_3 (Inverse): For all aGa \in G, there exists an aGa' \in G such that a+a=a+a=0.a + a' = a' + a = 0.

The cool thing about groups is that they’re very simple yet powerful: as long as any set paired with any binary operation satisfies these axioms, it forms a group, and all the theorems from group theory apply to it. It doesn’t just have to be R\mathbb{R} with the standard addition, anything from the set of square matrices (GL(n,C))(GL(n, \mathbb{C})) to the set of permutations on a regular nn-gon (S_n)(S\_n) form a group.

Let’s prove a theorem that will come in handy later. Since this post is going to be very technical, I’m not going to explain the proof since I’ll have to explain everything that builds onto the main theorem used in the proof, Lagrange’s Theorem.

Theorem: Let GG be a finite group under multiplication (so 1 is now the identity), and let G|G| denote its cardinality (order). Then for all aGa \in G,

a{G}=1.a^\{|G|\} = 1.

Proof: By Lagrange’s Theorem, the order of the element aa (the smallest positive integer kk such that ak=1a^k=1) must divide G|G|, that is, G=kn|G|=kn for some nNn \in \mathbb{N}. Then

a{G}=a{kn}=(ak)n=1n=1.a^\{|G|\}=a^\{kn\}=(a^k)^n=1^n=1. \quad \boxtimes

Let’s take a look at the specific group Z_p\mathbb{Z}\_p, consisting of the set of integers

0,1,2,...,p1\\{0,1,2, ... , p-1\\}

for pp a prime, paired with the binary operation of modular arithmetic. For example, 5+65+6 (mod 7) 11\equiv 11 (mod 7) 4\equiv 4. I’ll leave it to you to check that this forms a group. We can actually go further: we can tack on a second binary operation (modular multiplication) and call it a ring.

Rings have many properties, but the important ones are that multiplication is associative, follows the distributive law (a\*(b+c)=a\*b+a\*ca\*(b+c) = a\*b + a\*c), and that the ring has an identity for multiplication (there exists an element 1R1 \in R such that 1\*a=a\*1=a1\*a=a\*1=a for all aRa \in R). Formally, a ring that has an identity element is called a ring with unity.

The thing about rings is that not every element has a multiplicative inverse like groups do. For example, take the element 00. Since 0+0=00+0=0, a\*0=a\*(0+0)=a\*0+a\*0a\*0=a\*(0+0)=a\*0+a\*0 for all aRa \in R. If a\*0=a\*0+a\*0a\*0=a\*0+a\*0, just add the additive inverse of a\*0a\*0 to both sides of the equation to yield 0=a\*0+0=a\*00=a\*0+0=a\*0. So a\*0=0a\*0 = 0 for all aRa \in R. Now if 00 had a multiplicative inverse, that’s saying that there exists some element 0R0' \in R such that 0\*0=10'\*0=1, which is a contradiction since we would have both 0\*0=00'\*0=0 and 0\*0=10'\*0=1. Therefore 00 cannot have a multiplicative inverse.

Elements of rings that do have multiplicative inverses are called units. We have another handy theorem that lets us classify the units in Z_p\mathbb{Z}\_p! However, I’m going to skip explaning the machinery behind the proof for the same reasons as the first proof.

Theorem: Let nn be the order of the ring Z_n\mathbb{Z}\_n and mZ_nm \in \mathbb{Z}\_n. Then if gcd(m,n)=1,m\text{gcd}(m,n)=1, m is a unit.

Proof: Since gcd(m,n)=1\text{gcd}(m,n)=1, for some a,bZa, b \in \mathbb{Z}, we have an+bm=1an+bm=1 by Bezout’s Identity. By the Division Algorithm, we know there exist integers qq and rr such that 0rn10 \leq r \leq n-1 and b=nq+rb=nq+r. Then

rm=(bnq)m=bmnqm=(1an)nqm=1n(a+qm).rm = (b-nq)m = bm-nqm = (1-an)-nqm = 1 - n(a+qm).

Since we live in the ring Z_n\mathbb{Z}\_n, multiplication is commutative and multiples of nn will reduce to 00 (mod nn). Therefore n(a+qm)0n(a+qm) \equiv 0 (mod nn), and rm=mr=1rm=mr=1. Since we have found a multiplicative inverse for mZ_nm \in \mathbb{Z}\_n, we conclude that mm is a unit. \quad \boxtimes

There are special rings in which every non-zero element is a ring called fields. Intuively, fields are algebraic structures in which division is legal, since every element is a unit and therefore will remain in the field if “divided by” (multiplied by the multiplicative inverse) of another element in the field. From the previous theorem, the wonderful fact that Z_p\mathbb{Z}\_p is a field for pp a prime follows! Notice that every non-zero element of Z_p\mathbb{Z}\_p is relatively prime to pp (that is, gcd(m,p)=1(m,p)=1 for mZ_pm \in \mathbb{Z}\_p) since pp is a prime number, so every non-zero element of Z_p\mathbb{Z}\_p is a unit, hence Z_p\mathbb{Z}\_p is a field.

Algebra is all about analyzing structure. Like a phoenix rising from its ashes, a group emerges from this field. We claim that the set of units in Z_p\mathbb{Z}\_p form a group for pp a prime. The hardest part about showing that this is a group has already been done! That is, showing that every element has an inverse, which is trivial since every element is a unit.

We are ready to prove Fermat’s Little Theorem. Before we do, note that pp doesn’t necessarily have to be prime for the set of units in Z_p\mathbb{Z}\_p to from a group. However, since pp is prime, we know that every non-zero element is a unit, and therefore we can easily classify this group as consisting of the elements

1,2,3,...,p1\\{1,2,3, ... ,p-1\\}

and having order p1p-1. Let’s denote our new group as Z_p\*\mathbb{Z}\_p^\*. For convenience, we’ll restate Fermat’s Little Theorem.

Theorem (The Little Theorem of Fermat): Let aZa \in \mathbb{Z}, pp a prime. If pp doesn’t divide aa, then pp divides ap11a^{p-1} - 1, that is,

a{p1}1({mod}p).a^\{p-1\} \equiv 1 \, (\text\{mod\} \, p).

Proof: We can restate Fermat’s Little Theorem as such: For all aZ_p\*a \in \mathbb{Z}\_p^\*, ap11a^{p-1} \equiv 1 (mod pp). Recall a previous theorem: If GG is a finite group under multiplication, then aG=1a^{|G|}=1 for all aGa \in G. Clearly Z_p\*\mathbb{Z}\_p^\* is a finite group under multiplication, and the order of Z_p\*\mathbb{Z}\_p^\* is p1p-1, that is, Z_p\*=p1|\mathbb{Z}\_p^\*|=p-1. Therefore, for all aZ_p\*a \in \mathbb{Z}\_p^\*,

a{p1}a{{Z}_p\*}1({mod}p).a^\{p-1\} \equiv a^\{|\mathbb\{Z\}\_p^\*|\} \equiv 1 \, (\text\{mod\} \, p). \quad \boxtimes

(For the curious reader: Here is the reasoning behind why the two statements of FLT are equivalent. Every integer will correspond to a coset of the quotient ring Z/pZ.\mathbb{Z}/p\mathbb{Z}. In other words, if bZb \in \mathbb{Z}, then ba+pZb \in a+p\mathbb{Z} for some 0<ap10 \lt a \leq p-1 (aZ/pZ),(a \in \mathbb{Z}/p\mathbb{Z}), which implies a+pZ=b+pZa+p\mathbb{Z}=b+p\mathbb{Z} by the definition of cosets. So we can restate FLT as such: b+pZ,(b+pZ)p11\forall b+p\mathbb{Z}, (b+p\mathbb{Z})^{p-1} \equiv 1 (mod pp) which implies a+pZ,(a+pZ)p11\forall a+p\mathbb{Z}, (a+p\mathbb{Z})^{p-1} \equiv 1 (mod pp). Since Z/pZ\mathbb{Z}/p\mathbb{Z} and Z_p\mathbb{Z}\_p are naturally isomorphic as rings (similarily, Z/pZ\*\mathbb{Z}/p\mathbb{Z}^\* and Z_p\*\mathbb{Z}\_p^\* as groups), this statement is the same as aZ_p,ap11\forall a \in \mathbb{Z}\_p, a^{p-1} \equiv 1 (mod pp). Therefore, FLT is equivalent to the alternate statement.)

Once again, this post has grown quite long. I’ll wrap this series up in the next post, look forward to it!

by Simon Xiang