RSA Totient

Also known as phi n rsa · (p-1)(q-1) · euler totient of a semiprime · rsa phi

φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1)

Units aren’t used in this calculation — every value is a plain number.

Worked example: φ(3233) = 60 × 52 = 3120 — press Try an example to run it live, then adjust anything.

Enter your known values, leave one input blank, and solves for the missing one. Tap a variable’s symbol to see what it means, with a typical value.

Learning zone

RSA Totient explained

φpq

Euler's totient counts how many numbers below n share no factor with it. When n is a product of two distinct primes the count is easy to reason out: of the pqpq numbers below n, the multiples of p are q of them and the multiples of q are p of them, with 0 shared. Subtracting gives pq−p−q+1pq - p - q + 1, which factors as (p−1)(q−1)(p-1)(q-1). For the textbook key that is 60×52=312060 \times 52 = 3120.

φ(n) is what makes the encryption reversible. The private exponent d is chosen so that ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)}, and Euler's theorem then guarantees that raising to e and back to d returns the original message. This is also why φ is as secret as the primes themselves — hand someone φ(n) alongside the public n and they can recover p and q immediately, which is what the companion formula on this site does.

Two footnotes worth knowing. Modern implementations usually use the Carmichael function λ(n) = lcm(p−1, q−1) rather than φ, because it gives a smaller valid d and slightly faster decryption; φ still works and is what the original paper specified. And p must differ from q. If they are equal, n = p² and the count is p(p−1)p(p-1), not (p−1)2(p-1)^2 — the derivation above assumed the multiples of p and of q were different sets.

RSA Totient formula

φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1)
Where
  • φ\varphi= Totient
  • pp= First prime
  • qq= Second prime

Missing one of these? Work it out first, then come back