Lecture 14: Euler’s Totient Function: Counting the “Unrelated” Numbers

"Conceptual infographic art representing Euler's Totient Function for n=10. Show the numbers 1 through 10 arranged in a line. A stylized, semi-transparent 'sieve' or filter is passing over them. The numbers that share factors with 10 (2, 4, 5, 6, 8, 10) are being caught by the sieve and grayed out or made to look faded. The numbers that are relatively prime to 10 (1, 3, 7, 9) pass through the sieve and are brightly lit or colored. A text box at the end says 'φ(10) = 4'. The style is clean, symbolic, and educational, for a blog post on number theory."

Sequentia Explores: The Mathematics of Crypto

Part II: The Mathematician’s Toolkit

Lecture 14: Euler’s Totient Function: Counting the “Unrelated” Numbers

In our last lecture, we were amazed by the power of Fermat’s Little Theorem, which states that a^(p-1) ≡ 1 (mod p) when p is a prime number. This is a fantastic result, but it comes with a significant limitation: it only works when the modulus p is prime.

What if our modulus is a composite number? For instance, the RSA algorithm, which we’ve mentioned several times, operates mod n, where n is a large composite number (specifically, the product of two large primes). Fermat’s Little Theorem doesn’t directly apply. We need a more general tool.

That tool was provided by the brilliant 18th-century mathematician Leonhard Euler. He generalized Fermat’s theorem, and to do so, he introduced a wonderfully useful function: Euler’s Totient Function.

What is Euler’s Totient Function?

Euler’s totient function (also called Euler’s phi function) is written as φ(n) (where φ is the Greek letter phi).

The function φ(n) counts how many positive integers up to a given integer n are relatively prime to n.

Let’s refresh our memory: two numbers are “relatively prime” (or coprime) if their greatest common divisor (GCD) is 1. They share no common factors other than 1.

So, to calculate φ(10), we need to look at all the numbers from 1 to 10 and count how many of them have a GCD of 1 with 10.

  • GCD(1, 10) = 1 -> Yes (1 is always coprime)
  • GCD(2, 10) = 2 -> No (share a factor of 2)
  • GCD(3, 10) = 1 -> Yes
  • GCD(4, 10) = 2 -> No
  • GCD(5, 10) = 5 -> No
  • GCD(6, 10) = 2 -> No
  • GCD(7, 10) = 1 -> Yes
  • GCD(8, 10) = 2 -> No
  • GCD(9, 10) = 1 -> Yes
  • GCD(10, 10) = 10 -> No

The numbers relatively prime to 10 are {1, 3, 7, 9}. There are four of them.
Therefore, φ(10) = 4.

The set of these numbers {1, 3, 7, 9} is special. It’s the set of numbers less than 10 that have a multiplicative inverse mod 10. Remember, an inverse only exists if the number is coprime to the modulus! Euler’s totient function counts exactly how many such invertible numbers exist.

Calculating φ(n) – The Shortcuts

Counting by hand is fine for small n, but we need a faster way. Euler provided formulas for this.

Case 1: n is a prime number, p.
If n is a prime number, say p=7, which numbers from 1 to 7 are relatively prime to 7? Since 7 is prime, its only factors are 1 and 7. This means it shares no factors with any of the numbers {1, 2, 3, 4, 5, 6}. All of them are relatively prime to 7.
So, φ(7) = 6.
In general, for any prime p:
φ(p) = p – 1

Case 2: n is the product of two distinct prime numbers, p and q.
This is the most important case for the RSA algorithm. If n = p × q, there is a beautiful formula:
φ(n) = φ(p × q) = (p – 1) × (q – 1)

Let’s test this with our earlier example, n = 10. The prime factors of 10 are p=2 and q=5.
φ(10) = (2 – 1) × (5 – 1)
φ(10) = 1 × 4 = 4
It matches our manual count perfectly!

This formula is incredibly powerful. Even if n is a massive 600-digit number, if you know its two prime factors p and q, you can calculate φ(n) instantly. But if you don’t know the prime factors p and q, calculating φ(n) is computationally just as difficult as factoring n in the first place! This “trapdoor” nature—easy to compute with secret info (p and q), hard to compute without—is at the very heart of RSA’s security.

Euler’s Theorem: The Generalization of Fermat’s Little Theorem

Now we can introduce Euler’s masterpiece, which uses his totient function to generalize Fermat’s Little Theorem to composite moduli.

Euler’s Theorem states:

If n is a positive integer, and a is an integer that is relatively prime to n (i.e., GCD(a, n) = 1), then:
a^φ(n) ≡ 1 (mod n)

Look at the beautiful similarity to Fermat’s Little Theorem!

  • Fermat’s (for prime p): a^(p-1) ≡ 1 (mod p)
  • Euler’s (for composite n): a^φ(n) ≡ 1 (mod n)

Since φ(p) = p – 1, you can see that Fermat’s Little Theorem is just a special case of Euler’s Theorem when the modulus is a prime number.

The Engine of RSA

Let’s briefly revisit the RSA algorithm to see why this is so critical.

  • Alice chooses two secret primes, p and q.
  • She calculates n = p × q (part of her public key).
  • She calculates φ(n) = (p – 1) × (q – 1) (this value is kept secret).
  • She encrypts a message M by calculating C = M^e mod n.
  • She decrypts the ciphertext C by calculating M = C^d mod n.

How are e and d chosen? They are chosen to be modular multiplicative inverses of each other, mod φ(n). That is:
e × d ≡ 1 (mod φ(n))

When you work through the full proof (which we will in a later lecture), this relationship, combined with Euler’s Theorem, is what guarantees that (M^e)^d mod n will always simplify back to the original message M.

Without Euler’s totient function and his resulting theorem, the mathematical machinery of RSA would simply fall apart. It provides the precise exponent (φ(n)) needed to make the “clock arithmetic” of modular exponentiation work in our favor, allowing decryption to be the perfect inverse of encryption.

Euler’s totient function, therefore, is not just a simple counting exercise. It’s the key that unlocks Fermat’s powerful ideas for the world of composite numbers, paving the way for the public-key cryptography that secures our digital world.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top