%3C/text%3E%3C/svg%3E">
💻
💻 Tech & IT

RSA Key Math Calculator (educational, small primes)

Results update as you type.

Your numbers

Understanding the RSA key math calculator — concept and principle

RSA is the public-key system behind many digital signatures and key exchanges. This calculator runs textbook RSA with tiny primes so you can follow every step: building the modulus, finding the private exponent, encrypting a number and decrypting it again. It is meant for students and anyone who wants to see why RSA works.

RSA with p = 61 and q = 53n = 3,233 and φ(n) = 3,120; public e = 17, private d = 2,753. Message 65 encrypts to 2,790 and decrypts back to 65.RSA: lock with e, unlock with dp = 61×q = 53→n = 3,233φ(n) = 60 × 52 = 3,120 · 17 × 2,753 = 15 × 3,120 + 1Public keye = 17Private keyd = 2,753m = 6565¹⁷ mod nc = 2,790c²⁷⁵³ mod n65back to 65Real RSA uses primes hundreds of digits long
Anyone can lock 65 into 2,790 with e = 17, but only d = 2,753 opens it again.

How it is calculated

  1. Choose two primes p and q and form the modulus n = p × q.
  2. Compute Euler's totient φ(n) = (p − 1)(q − 1).
  3. Pick a public exponent e with gcd(e, φ(n)) = 1. The calculator stops if e is not coprime with φ(n), or if p or q is not prime.
  4. Find the private exponent d = e⁻¹ mod φ(n), the number with e × d ≡ 1 (mod φ(n)). The tool uses the extended Euclidean algorithm.
  5. Encrypt a message number m (0 ≤ m < n): c = mᵉ mod n. Decrypt: m = cᵈ mod n. Powers are computed by square-and-multiply with exact big integers.

The principle

Euler's theorem says m^φ(n) ≡ 1 (mod n) when m and n share no factor. Since e × d = 1 + t × φ(n) for some whole number t, raising c = mᵉ to the power d gives m^(1 + tφ(n)) = m × (m^φ(n))^t ≡ m. (With the Chinese remainder theorem the result also holds for every m below n.) The security rests on the fact that n and e are public but computing d needs φ(n), and finding φ(n) is as hard as factoring n. Factoring 3,233 is instant; factoring a 2,048-bit modulus is far beyond current computers.

Worked example

  1. Inputs: p = 61, q = 53, e = 17, m = 65.
  2. n = 61 × 53 = 3,233.
  3. φ(n) = 60 × 52 = 3,120. gcd(17, 3,120) = 1, so e is valid.
  4. d = 2,753, because 17 × 2,753 = 46,801 = 15 × 3,120 + 1.
  5. c = 65¹⁷ mod 3,233 = 2,790.
  6. 2,790^2,753 mod 3,233 = 65, the original message.

How to read the result

If decryption returns the original m, the key pair is consistent. Getting a different number usually means m ≥ n, which cannot be represented uniquely. Common real-world e is 65,537; real moduli are 2,048 bits or more.

Common mistakes

Keep in mind: This is a learning tool. Real RSA uses large random primes, padding such as OAEP for encryption or PSS for signatures, and a vetted cryptographic library. Never use tiny keys or hand-written RSA code to protect real data.

Frequently asked questions

Why is e = 65,537 so common?

It is prime, has only two 1-bits in binary, so encryption and signature checks are fast, and it is large enough to avoid known small-exponent attacks when padding is used.

Can I use Carmichael's λ(n) instead of φ(n)?

Yes. Many libraries compute d modulo λ(n) = lcm(p − 1, q − 1), which gives a smaller but equally valid d.

How large should RSA keys be today?

Current guidance treats 2,048 bits as the minimum for general use, with 3,072 bits for longer-term protection.

Sources: R. L. Rivest, A. Shamir, L. Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM 21(2), 1978 · IETF RFC 8017, PKCS #1: RSA Cryptography Specifications Version 2.2 · NIST SP 800-57 Part 1, Recommendation for Key Management

Checked 8 Nov 2026. Standard formulas and RFC/IEEE definitions, computed locally in your browser — nothing you type is sent anywhere.

💻 All tech & IT tools →🌍 Calculators by country →