Clicky

Go back to the blockchain category
Go back to previous page
Extended Euclidean Algorithm
Fermat's little theorem

Fermat's little theorem

Fermat's little theorem is a fundamental theorem in number theory that is named after Pierre de Fermat, a 17th-century French lawyer and mathematician. The theorem is a simple yet powerful tool that helps to prove the primality of numbers and is widely used in cryptography, computer science, and other areas of mathematics.

Statement of the Theorem

The statement of Fermat's little theorem is quite simple: If p is a prime number and a is any integer not divisible by p, then a^(p-1) ≡ 1 (mod p). In other words, if you take any integer a that is not a multiple of a prime number p, and raise it to the (p-1)th power, then divide the result by p, the remainder is always 1.

Proof of the Theorem

The proof of Fermat's little theorem is based on modular arithmetic. If a is not divisible by p, then we can define the set {a, 2a, 3a, ..., (p-1)a} modulo p.

This set contains p-1 unique elements, because in order for two of the elements to be congruent 'ia' would have to be equal to ja (mod p) => ia = ja (mod p), this means the remainder of 'ia' divide by the number 'p' would be equal to the remainder of 'ja' divide by 'p', with i < j this would imply that (j-i)a ≡ 0 (mod p), because another way to write: ia = ja (mod p) is ia = p*k + ja, where k is an arbitrary number, this means that ja-ia = p*k which is equal to (j-i)a ≡ 0 (mod p), and since 'a' is not divisible by 'p', this would imply that j-i is divisible by 'p', which contradicts the assumption that was used to define the set i < j ≤ p-1. It is also clear that none of the elements of the set is equal to zero modulo p.

Thus, each element of the set is congruent to one of the numbers 1, 2, 3, ..., p-1, and no two are congruent to the same number.

Now, we multiply all the elements of the set together and obtain:

a*(2a)*(3a)...((p-1)a) ≡ 1*2*3...*(p-1) (mod p)

The left-hand side can be written as a^(p-1)(1*2*3...(p-1)). Since 1*2*3...*(p-1) is simply (p-1)!, we get:

a^(p-1)*(p-1)! ≡ (p-1)! (mod p)

Cancelling (p-1)! from both sides of the congruence, we obtain:

a^(p-1) ≡ 1 (mod p)

which is the statement of Fermat's little theorem.

Applications of the Theorem

Fermat's little theorem has numerous applications in number theory, cryptography, and computer science. Here are some examples:

  • Primality testing: Given a number n, Fermat's little theorem can be used to test whether n is prime or not. If a^(n-1) ≡ 1 (mod n) for some integer a, then n is likely to be prime (although this is not a foolproof test).

  • RSA encryption: The RSA cryptosystem is based on the difficulty of factoring large composite numbers. Fermat's little theorem is used to encrypt messages in RSA by raising them to a certain power modulo a large composite number. The theorem guarantees that the decryption will work correctly, as long as certain conditions are met.

  • Pseudorandom number generation: Fermat's little theorem is used in the generation of pseudorandom numbers, which are used in many applications such as simulations and gaming. The idea is to take a large prime number p and a random integer a not divisible by p, and then generate a sequence of numbers by taking a^(k) modulo p for various values of k. The resulting sequence of numbers is pseudorandom in the sense that it appears to be random, but is actually deterministic and can be reproduced if the same values of p and a are used.

  • Modular exponentiation: Computing a^b modulo a large number is a common operation in many algorithms, such as in the calculation of hash functions. Fermat's little theorem can be used to simplify the computation of large powers modulo a prime number. For example, if we want to compute a^b modulo p, we can reduce the exponent b modulo p-1 using Fermat's little theorem, and then use repeated squaring to compute the result efficiently.

  • Discrete logarithm problem: The discrete logarithm problem is a fundamental problem in number theory and cryptography. Given a prime p, an integer g not divisible by p, and an integer h, find an integer x such that g^x ≡ h (mod p). This problem is believed to be hard to solve for large values of p, and many cryptographic protocols rely on the difficulty of this problem.

Conclusion

Fermat's little theorem is a powerful tool in number theory, cryptography, and computer science. It provides a simple and elegant way to prove the primality of numbers, and has numerous applications in encryption, pseudorandom number generation, and other areas of mathematics. By understanding the theorem and its applications, one can gain a deeper appreciation for the beauty and power of number theory.