The Black Chamber RU

Tools · Modern cryptography

RSA calculator for learning

RSA with small numbers: primes p and q, keys, encryption and decryption, factoring n.

Runs in your browser. Your text goes nowhere.

How to use it

At the top is the public key: the numbers n and e. If the d field is empty, the tool factors n into two primes by itself (with Pollard’s rho method), computes φ(n) = (p − 1)(q − 1) and the private exponent d. Up to 22 digits that happens instantly; for bigger numbers press “Factor n” and be patient. That patience is exactly what protects RSA.

In “Decrypt” mode, paste the ciphertext: numbers separated by spaces, commas or new lines; brackets don’t get in the way. Each number c becomes m = cd mod n. Below, the same numbers are shown as letters: A = 1 … Z = 26, or the 33-letter Russian alphabet with ё. The table under the result shows every step.

In “Encrypt” mode, type a word (its letters become their numbers and are encrypted one at a time) or the numbers themselves. Every number must be smaller than n.

Your own keys

“Make keys from two primes” builds a key pair from p, q and e and checks that everything is right: both numbers prime and different, and e sharing no factor with φ(n). The “Random primes” buttons pick p and q of the length you want. The last block shows the extended Euclidean algorithm that turns e and φ(n) into d.

FAQ

Why is encrypting one letter at a time bad?

Equal letters give equal numbers, so the cipher turns into a simple substitution, which frequency analysis breaks. Real RSA encrypts big numbers with random padding (the OAEP scheme), and most often it encrypts not the text itself but a key for AES.

How big are the numbers in real RSA?

Today n is usually 2048 or 3072 bits, more than 600 digits. The largest number factored from the public RSA challenge, RSA-250, has 250 digits; factoring it in 2020 took about 2,700 years of computer time.

What is e = 65537?

The most common public exponent in real keys: in binary it’s a 1, fifteen 0s and another 1, which makes raising to that power fast. It’s often too big for small classroom values of n, so this tool defaults to 17.

For why all this works, see the lesson on public keys. Everything is computed in your browser.