Skip to main content

Fermat's little theorem

Consider modular arithmetic under modulo mm. We fix number aa so that gcd(a,m)=1{\sf gcd}(a,m)=1. Let us write a function fa:[m1][m1]f_a: [m-1] \rightarrow [m-1] where fa(x)=ax(modm)f_a(x) = a \cdot x \pmod{m}. We argued before (when we proved that the inverse exists) that faf_a is a bijection. Therefore,

x[m1]{0}xx[m1]{0}ax(modm)\prod_{x\in[m-1]\setminus \{0\}} x \equiv \prod_{x \in [m-1]\setminus \{0\}}a\cdot x \pmod{m}

This gives us (am11)(m1)!0(modm)(a^{m-1}-1)(m-1)! \equiv 0 \pmod{m}. Equivalently, mm divides (am11)(m1)!(a^{m-1}-1)(m-1)!. When mm is prime, we know that mm divides am11a^{m-1} -1.

Theorem 18 (Fermat's little theorem (F\ellT))

For any prime pp and number aa that is not divisible by pp, we have ap11(modp)a^{p-1} \equiv 1 \pmod{p}.

Remark the distinction between the elementary F\ellT and the much-more-difficult-to-prove Fermat's Last Theorem (FLT). The correctness of RSA follows from a simple application of F\ellT.

Theorem 19 (Correctness of RSA)

We have that xedx(modN)x^{e\cdot d} \equiv x \pmod{N}.

Proof:

Since ed1(mod(p1)(q1))e \cdot d \equiv 1 \pmod{(p-1)(q-1)}, we can write ed=1+k(p1)(q1)e \cdot d = 1+ k (p-1)(q-1) for some integer kk. Therefore,

xedx1+k(p1)(q1)(modN)x^{e \cdot d} \equiv x^{1+k(p-1) (q-1)} \pmod{N}

We argue that x1+k(p1)(q1)x(modp)x^{1+k(p-1)(q-1)} \equiv x \pmod{p} and x1+k(p1)(q1)x(modq)x^{1+k(p-1)(q-1)} \equiv x \pmod{q}, which would imply the desired result (do you see why?). We only prove the former claim (the latter case is symmetrical). To prove x1+k(p1)(q1)x(modp)x^{1+k(p-1)(q-1)} \equiv x \pmod{p}, we consider two cases:

  • If xx is divisible by pp, notice that x1+k(p1)(q1)xx^{1+k(p-1)(q-1)} - x is also divisible by pp.
  • If xx is not divisible by pp, we can apply F\ellT to obtain xp11(modp)x^{p-1} \equiv 1 \pmod{p} and therefore x1+k(p1)(q1)x(modp)x^{1+k(p-1)(q-1)} \equiv x \pmod{p}.
Exercise 49

Prove that x10≢1(mod31)x^{10} \not\equiv -1 \pmod{31} for all integer xx. Your proof should be at most a few lines (in particular, do not list all possible choices of xx).