Math calculator

RSA Calculator

Key generation and a round trip, on numbers you can follow.

Key generation, and a round trip

Primes small enough to factor instantly — which is the point.

public key (n = 3233, e = 17)

d = 2753

Message 65 encrypts to 2790 and decrypts back to 65 — the round trip holds.

n = p × q

3233

public — the modulus

φ(n)

3120

secret — needs p and q

Public exponent e

17

public, coprime with φ(n)

Private exponent d

2753

the modular inverse of e

Ciphertext

2790

mᵉ mod n

Decrypted

65

cᵈ mod n

  • n = p × q = 3233 is public. φ(n) = (p − 1)(q − 1) = 3120 is secret, and computing it requires knowing p and q — which is the entire security of the scheme.
  • The private key d is the modular inverse of e modulo φ(n): 17 × 2753 ≡ 1 (mod 3120). Encryption raises to the power e and decryption to the power d, and they undo each other because of Euler’s theorem.
  • References disagree about d, and both are right. The original RSA paper uses Euler’s φ(n) = (p − 1)(q − 1), which is what this page does. Modern implementations use Carmichael’s λ(n) = lcm(p − 1, q − 1), which is a divisor of φ(n) and yields a smaller d. Every such d decrypts correctly — so a d that differs from a textbook’s is not necessarily wrong, and the round trip below is the check that matters.
  • The security rests on factoring being hard, NOT on the exponentiation being hard. Anyone who can factor n can compute φ(n) and then d in a moment — so the difficulty is entirely in the factorisation.
  • These primes are tiny and can be factored instantly, which is exactly why they are safe to demonstrate with. Real RSA uses primes of roughly 300 digits each, giving a 2048-bit modulus.
  • This is TEXTBOOK RSA, and textbook RSA is insecure even with large primes. It is deterministic, so the same message always gives the same ciphertext, and short messages can be recovered by taking an ordinary integer root. Real implementations pad with OAEP for exactly these reasons.

This is textbook RSA and it is insecure even with large primes. Real implementations pad with OAEP, and this page is for understanding the mechanism only.

What this tool shows

The security rests on factoring being hard, not on the exponentiation being hard. Anyone who can factor n can compute φ(n) and then the private key in a moment — which is why the primes here, being tiny, are safe to show.

  • Generating a key pair from two primes
  • What is public and what is secret
  • Encrypting and decrypting a message
  • Why the round trip works
  • Why textbook RSA is insecure
  • Why references disagree about d
Key generation A full round trip Honest about security Small primes on purpose

Textbook RSA, for understanding the mechanism only.

Updated 7 September 2026 · Works in any browser, no installation

The security is factoring, not exponentiation. n = pq is public and φ(n) = (p−1)(q−1) is secret — but anyone who can factor n can compute φ(n) and then the private key immediately. So RSA is exactly as strong as factoring is hard, and no stronger.

At a glance

Formula shown
n = pq and φ(n) = (p − 1)(q − 1). Choose e coprime with φ(n); the private key d satisfies ed ≡ 1 (mod φ(n)). Encryption is c = mᵉ mod n and decryption m = cᵈ mod n.
Scenario support
Learning how public-key cryptography works; following a textbook RSA exercise; seeing why key size matters.
Educational estimate
Planning support from the values you enter — not professional advice.

What each number is

Six numbers, and knowing which are public is the whole picture.

p and q are two distinct primes. Secret, and after key generation they can be discarded — though keeping them speeds decryption up considerably.

n = pq is the modulus. Public. Everyone sees it.

φ(n) = (p−1)(q−1) counts the numbers below n that are coprime with it. Secret, and this is the crux: computing it requires knowing p and q.

e is the public exponent, chosen coprime with φ(n). Public. In practice it is almost always 65537, which is prime and has only two bits set, making exponentiation fast.

d is the modular inverse of e. Secret, and it is the private key.

Why the round trip works

Encrypting raises to the power e; decrypting raises to the power d. They undo each other, and the reason is Euler’s theorem.

Euler’s theorem says m^φ(n) ≡ 1 (mod n) whenever m is coprime with n. Since ed ≡ 1 (mod φ(n)), we have ed = 1 + kφ(n) for some k, so m^ed = m × (m^φ(n))^k ≡ m × 1 ≡ m.

That is the whole proof. Encryption and decryption are the same operation with different exponents, and the exponents were chosen so that applying both returns the original.

It also works when m shares a factor with n, though that needs the Chinese remainder theorem rather than Euler’s theorem directly — and if it happened you would have factored n by accident, which is a far bigger problem than the message.

Why this is not secure

Two separate reasons, and both matter.

The primes here are tiny. A 100,000-limit prime is factored instantly, so anyone can derive the private key from the public one. That is deliberate: numbers small enough to be broken are the ones safe to demonstrate with, and small enough to follow by hand.

Textbook RSA is insecure even with large primes. This is the part that surprises people.

It is deterministic: the same message always gives the same ciphertext, so an attacker who can guess the plaintext can confirm it by encrypting. For a message that is one of a few possibilities — yes or no, a price, a name from a list — that is fatal.

Short messages can be recovered outright. If mᵉ is smaller than n, no wrapping happens and taking an ordinary integer eth root recovers m with no key at all.

It is also malleable: multiplying a ciphertext by 2ᵉ multiplies the plaintext by 2, without the key.

Real implementations pad with OAEP, which adds randomness and structure and removes all three problems. RSA without padding is not RSA as anyone deploys it.

Why references disagree about d

Work an RSA example from two textbooks and you may get two different private keys. Both can be right.

The original 1978 paper uses Euler’s totient, φ(n) = (p−1)(q−1). That is what this page uses.

Modern implementations use Carmichael’s function, λ(n) = lcm(p−1, q−1). It is a divisor of φ(n), so it gives a smaller d — which makes decryption faster.

Every d produced either way decrypts correctly, because both satisfy the congruence that the proof needs. So a d that differs from a textbook’s is not necessarily wrong.

The check that matters is the round trip, which this page performs and displays. That is why the test suite verifies by round trip rather than by matching a published key.

Where it gets used

TLS. RSA has long been used to exchange keys when a browser connects to a site, though elliptic-curve methods have largely displaced it for that.

Signatures. Signing runs the operation the other way: the private key produces something anyone with the public key can verify. Code signing, certificates and document signing all rest on it.

SSH and PGP. RSA key pairs remain common for both.

Its future. Shor’s algorithm factors efficiently on a sufficiently large quantum computer, which would break RSA outright. No such machine exists, and post-quantum standards are being adopted in anticipation — a reminder that the security assumption is about difficulty, not impossibility.

Sources and methodology

RSA is a published algorithm; these are the references.

Method. Everything runs on arbitrary-precision integers, and the primes are capped at 100,000 — small enough to factor instantly, which is exactly what makes them safe to demonstrate with. The suite verifies correctness by round trip rather than by matching a published key: this page uses Euler’s φ(n) where many references use Carmichael’s λ(n), which yields a different but equally valid private key, so only the round trip distinguishes right from wrong. That engine is verified on every change against 99 hand-written assertions, including that every message below n round-trips correctly across three key pairs, and that a non-prime input, equal primes, and an exponent sharing a factor with φ(n) are each refused with the reason. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Modular Exponentiation7^128 mod 13 without ever building the 109-digit power. Square-and-multiply is shown one exponent bit at a time, with the count of multiplications it saved.
Modular InverseThe number that undoes a multiplication modulo n, from the extended Euclidean algorithm — or the shared factor that proves no such number exists.
Prime NumberWhether a number is prime, with a divisor named when it is not and the size of the search stated when it is. Deterministic, not probabilistic.
CoprimeSet coprimality and pairwise coprimality are different conditions: 6, 10 and 15 have gcd 1 and not one coprime pair. Both are reported, with the offending pairs named.
ModuloAll three conventions at once, because −7 mod 3 is −1 in JavaScript and 2 in Python and a page that gives only one of those is wrong for half its readers.
Luhn AlgorithmValidate a number or generate its check digit, with the doubling shown — and a live test of whether it catches a transposition, which is what a digit sum cannot.

More in Math, or browse all calculators.

Read the guide

The modular exponentiation that RSA is built on has its own page, with the square-and-multiply method shown.

Educational use disclaimer

This is an educational tool. It implements textbook RSA, which is insecure even with large primes. Never use it for anything real.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the RSA page with primes capped at 100,000 — small enough to factor instantly, which is exactly what makes them safe to demonstrate with, and the page says so rather than implying the numbers are meaningful.
  2. States plainly that this is textbook RSA and that textbook RSA is insecure even with large primes: it is deterministic, short messages can be recovered by taking an ordinary integer root, and it is malleable. Real implementations pad with OAEP.
  3. Explains why references disagree about d — the original paper uses Euler's φ(n) and modern implementations use Carmichael's λ(n), giving a smaller but equally valid key — which is why the suite verifies by round trip rather than by matching a published example.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.