RSA Private Exponent Calculator

Enter the public exponent e and the totient φ(n) to compute the private exponent d.

How it is calculated

The tool finds d with e × d ≡ 1 (mod φ) using the extended Euclidean algorithm, which writes gcd(e, φ) = 1 as s·e + t·φ; the coefficient s, reduced into the range 0 to φ−1, is d. A second line, "check", multiplies e by d modulo φ and should always show 1. Both inputs must be whole numbers: e at least 1, φ at least 2, and neither above 253 (9007199254740992), because larger values cannot be held exactly. If e and φ share a common factor there is no inverse and the tool returns no result. An e larger than φ is accepted and behaves like e mod φ. This is a teaching tool for small numbers; it takes φ(n) as given and does not factor n or build a key.

Worked example

Take the textbook key with p = 61 and q = 53. Then φ = (61 − 1)(53 − 1) = 3120, and let e = 17. Euclid gives 3120 = 183·17 + 9, 17 = 1·9 + 8, 9 = 1·8 + 1. Working back, 1 = 2·3120 − 367·17, so e⁻¹ ≡ −367, which is 3120 − 367 = 2753. The tool shows d = 2,753. Check: 17 × 2753 = 46,801 = 15 × 3120 + 1, so the remainder is 1.

Try this example →

Common mistakes

  • Entering n instead of φ(n). With p = 61 and q = 53, n is 3233 but φ is 3120; using n gives a d that does not decrypt anything.
  • Choosing an e that shares a factor with φ. An even e never works because φ is even, and for φ = 3120 any e divisible by 2, 3, 5 or 13 returns no result.
  • Calculating φ as p × q − 1 or (p − 1) + (q − 1). For two primes it is (p − 1)(q − 1), here 60 × 52.
  • Copying the displayed d with its thousands separator (2,753 or, in some locales, 2.753) into code. Remove the separator before using the number.
  • Expecting to enter real 2048-bit key values. Inputs above 253 are rejected, so use a library for production keys; this tool is for learning with small primes.

Sources

About this calculator

RSA key generation picks a public exponent e and computes the private exponent d as its modular inverse with respect to Euler's totient of the modulus: d ≡ e⁻¹ (mod φ(n)), meaning d is the unique value satisfying e·d ≡ 1 (mod φ(n)). It's found using the extended Euclidean algorithm rather than by simple division.

Cryptography students and instructors use this calculator to work through RSA key generation by hand and verify their arithmetic, and security engineers use it to sanity-check a manually constructed key pair or to understand exactly how e, φ(n) and d relate before implementing RSA in code.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Once you have d, test the pair with a round trip, which this tool does not perform. With n = 3233, e = 17 and d = 2753, the message 65 encrypts to 65 raised to 17 mod 3233, which is 2790, and 2790 raised to 2753 mod 3233 returns 65. If the message does not come back, recheck that you used phi, not n. Are you working through a textbook exercise or your own small example?

Popular calculators

All Calculators