CryptoBook
  • CryptoBook
  • Book Plan
  • Style Guide
    • Sample Page
  • Contributors
  • Fundamentals
    • Mathematical Notation
    • Division and Greatest common divisor
      • Euclidean Algorithm
    • Modular Arithmetic
      • Theorems of Wilson, Euler, and Fermat
        • Fermat's Little Theorem in Detail
        • Euler's Theorem in Detail
      • Quadratic Residues
    • Continued Fractions
  • Number Theory
  • Ideals
  • Polynomials With Shared Roots
  • Integer Factorization
    • Pollard rho
    • Sieves
  • Abstract algebra
    • Groups
      • Another take on groups
      • Discrete Log Problem
    • Rings
    • Fields
    • Polynomials
  • Elliptic Curves
    • Untitled
  • Lattices
    • Introduction
    • LLL reduction
      • Gram-Schmidt Orthogonalization
      • Lagrange's algorithm
      • LLL reduction
    • Lattice reduction
      • Minkowski reduced
      • HKZ reduced
      • LLL reduced
    • Applications
      • Coppersmith algorithm
      • Extensions of Coppersmith algorithm
    • Hard lattice problems
    • Lattices of interest
    • Cryptographic lattice problems
      • Short integer solutions (SIS)
      • Learning with errors (LWE)
      • Ring-LWE
      • NTRU
    • Interactive fun
    • Resources and notations
  • Asymmetric Cryptography
  • RSA
    • Proof of correctness
    • RSA application
    • Low Private Component Attacks
      • Wiener's Attack
      • Boneh-Durfee Attack
    • Common Modulus Attack
    • Recovering the Modulus
  • Diffie-Hellman
    • MITM
  • Elliptic Curve Cryptography
  • Symmetric Cryptography
    • Encryption
    • The One Time Pad
    • AES
      • Rijndael Finite Field
      • Round Transformations
  • Hashes
    • Introduction / overview
    • The Birthday paradox / attack
  • Isogeny Based Cryptography
    • Introduction to Isogeny Cryptography
    • Isogenies
    • Isogeny and Ramanujan Graphs
  • Appendices
    • Sets and Functions
    • Probability Theory
Powered by GitBook
On this page
  • Introduction
  • Fermat's Little Theorem

Was this helpful?

Export as PDF
  1. Fundamentals
  2. Modular Arithmetic
  3. Theorems of Wilson, Euler, and Fermat

Fermat's Little Theorem in Detail

Would you like to be an author?

Introduction

Since we can add, subtract, multiply, divide even... what would be missing? Powering! I'm not talking about some power fantasy here, but rather introduce some really really important theorems. Fermat little's theorem proves useful in a great deal of situation, and is along with Euler's theorem a piece of arithmetic you need to know. Arguably the most canonical example of using these is the RSA cryptosystem, whose decryption step is built around Euler's theorem.

Fermat's Little Theorem

Since we want to talk about powers, let's look at powers. And because I like 7, I made a table of all the powers of all the integers modulo 7.

Power

0

1

2

3

4

5

6

1

0

1

2

3

4

5

6

2

0

1

4

2

2

4

1

3

0

1

1

6

1

6

6

4

0

1

2

4

4

2

1

5

0

1

4

5

2

3

6

6

0

1

1

1

1

1

1

On the last row, there is a clear pattern emerging, what's going on??? Hm, let's try again modulo 5 this time.

Power

0

1

2

3

4

1

0

1

2

3

4

2

0

1

4

4

1

3

0

1

3

2

4

4

0

1

1

1

1

Huh, again?! Clearly, there is something going on... Sage confirms this!

p, itworks = 1, True
for _ in range(100):
    p = next_prime(p)
    Fp = GF(p) # Finite Field of size p
    itworks &= all(Fp(x)^(p-1) == 1 for x in range(1,p))

print(itworks)
# True

Claim (Fermat's Little Theorem): Letpppa prime.∀a∈Z,ap≡a [p]\forall a\in\mathbb Z, a^p\equiv a~[p]∀a∈Z,ap≡a [p]

Whena≠0a\neq 0a=0, this is equivalent to what we observed:ap−1≡1 [n]a^{p-1}\equiv 1~[n]ap−1≡1 [n]. There are several proofs of Fermat's Little Theorem, but perhaps the fastest is to see it as a consequence of the Euler's Theorem which generalizes it. Still, let's look a bit at some applications of this before moving on.

A first funny thing is the following:∀a∈Z,a⋅ap−2≡ap−1≡1 [p]\forall a\in\mathbb Z, a\cdot a^{p-2}\equiv a^{p-1}\equiv 1~[p]∀a∈Z,a⋅ap−2≡ap−1≡1 [p]. Whenp>2p>2p>2, this means we have found a non-trivial integer that when multiplied toaaayields 1. That is, we have found the inverse ofaaa, wow. Since the inverse is unique moduloppp, we can always invert non-zero integers by doing this. From a human point of view, this is really easier than using the extended euclidean algorithm.

PreviousTheorems of Wilson, Euler, and FermatNextEuler's Theorem in Detail

Last updated 3 years ago

Was this helpful?