Skip to main content

Fermat's little theorem

In my post on RSA encryption system I mentioned the use of Fermat's little theorem. In this post I am going to give a formal proof (and explain in simple terms) the theorem itself. This will also give you a chance to boast among your friends (possibly nerdy) that you know the proof to one of Fermat’s theorem ;)

THE STATEMENT

Fermat's little theorem states that:
For any integer a not divisible by p and any prime p, the following always holds: a(p-1) ≡ 1 (mod p)
The reason why the theorem states that a should not be divisible by p is very clear. Let us assume that a was divisible by p, then obviously p will divide a(p-1).
So this means that a(p-1) ≡ 0 (mod p) when p | a. So this is an exception and is separately mentioned in the theorem.

PROOF

Now coming to the actual proof of the theorem. If we see the left hand side of the equation in the statement, we have the term a(p-1). So it is clear that this was obtained by multiplying a, p-1 times.

Now let us take a look at the first p-1 multiples of a. These are:
a, 2a, 3a, ..., (p-1)a
In general two different multiples of a can be expressed as ra, sa (where r≠ s, and r, s <= p-1)
Now we will try to find the properties of the remainders obtained when these multiples are divided by p-1. We claim that all the remainders obtained will be distinct and will cover the range 1, 2, ... , p-1.
Now to prove the above claim we assume that it is false and then obtain a contradiction. So we assume that there exists some r and s such that ra ≡ sa (mod p).(where r≠ s, and r, s <= p-1)
Solving the above equation, we can cancel out a from both sides and be left with r ≡ s (mod p). But this is not possible. As both r is less than p, hence when divided by p it will give a remainder r itself and hence r = s. However we started out with the assumption that ra and sa were two distinct multiples of a, but we came to the conclusion that the remainders of the two with p, can be same iff they are the same multiples.
Hence, all the first (p-1) multiples of a have unique remainders modulo p. And since the remainder of a number modulo x ranges from 0 to x-1, so the remainder modulo p, will also range from 0 to p-1. Moreover we claim that none of them will have a remainder 0 as it is already stated that p ∤ a.

So now we know that the remainder of the numbers a, 2a, ..., (p-1)a are in the range 1, 2, ..., p-1. Now let us multiply all these numbers together and take them modulo p (remembering the fact that we need a(p-1) on the LHS)
So we get,
a.2a.3a...(p-1)a ≡ 1.2.3...(p-1) (mod p)
(p-1)!. a(p-1) ≡ (p-1)! (mod p)
Cancelling (p-1)! from both sides we get,
a(p-1) ≡ 1 (mod p)
Which was the original statement that we had to prove!

THE USE OF LITTLE THEOREM

 Although asking about the use of a theorem is an insult to a pure mathematician, but Fermat’s little theorem shows us that how a pure number theory related theorem can be used in something so modern.
The Little theorem dates back to 1640s and as we already saw in the RSA blog post, RSA was conceptualized in 1970s and is still in active use.
The basis of RSA is formed using Fermat's little theorem. Finally I would like to end with a quote from G.H Hardy, one of the best contemporary number theorist     
Pure mathematics, may it never be of any use to anyone.
This clearly sums up the fact that mathematician don't actually care if their theorem can be applied to some practical use or not, but when it does it creates something as beautiful as the RSA!
 


 

Comments

Popular posts from this blog

Streaming Algorithms - Lossy Counting

We had a discussion recently in our office on one of the famous  streaming algorithms  known as lossy count. I decided to write down my understanding of it focusing on the space complexity discussion and proving why it works in logarithmic space. This  is the original paper introducing this algorithm and most of the information discussed in this blog is (hopefully) a simplified version of this paper relating to lossy count. Problem Statement There are use cases where you may be receiving a continuous stream of data and you want to know which items in that data stream exceed a certain threshold. The data stream could be really big so you can't store it in memory. Moreover you want to answer queries in real time. So here are the challenges this problem imposes: 1. Need to do it in single pass (time constraint) 2. Limited memory 3. Large volume of data in real-time The above issues warrant the need of a smart counting algorithm. Data stream mining to identify events & pa...

RSA Encryption System

THE NEED OF ENCRYPTION In today's world where a lot of secured information like our credit card number, passwords etc., travel around the web, the presence of a secure encryption system is almost inevitable. We want a method to encrypt a message, send it over the insecure internet connection and allow only the receiver to be able to decrypt and read the original message. This exact problem was solved by R ivest, S hamir and A dleman(RSA) in the year 1978, in their paper A Method for Obtaining Digital Signatures and Public-Key Cryptosystems. In this post, I will try to explain the method they adopted to create a secure encryption system. PUBLIC KEY CRYPTOSYSTEM A public key cryptosystem has the following properties: 1) D(E(M)) = M, if we decrypt an encrypted message, we should get back the message. 2) Both E and D should be easy to compute, if it takes days to encrypt or decrypt the message, then the cryptosystem is not very useful. 3) By publicly revea...