b2KIT

RSA Algorithm Visualizer

Step through RSA key generation, encryption, and decryption with small primes. Shows modular exponentiation and Euler totient.

Tested tool guide Tested browser tools Checked August 16, 2026

What RSA Algorithm Visualizer does, with a checked example

Textbook RSA runs on arithmetic small enough to hold in your head, and this tool makes every step visible. Give it two small primes p and q plus a public exponent e, and it computes the modulus n, the Euler totient (p-1)(q-1), and the private exponent d, then encrypts a message by modular exponentiation and decrypts it back, showing each multiplication and reduction. The surprise most people hit: the plaintext must be smaller than n. With n = 33 you can only encrypt values 0 to 32; a larger message reduces to its remainder before exponentiation, so a message of 40 decrypts back to 7, not to 40.

Worked example

A concrete input and expected output from the current implementation.

Input

p = 3, q = 11, e = 7, message m = 5

Expected output

n = 3 * 11 = 33. Totient = (3-1)(11-1) = 20. d = 3, since 7 * 3 = 21 leaves remainder 1 when divided by 20. Public key (33, 7), private key (33, 3). Ciphertext: c = 5^7 mod 33 = 14 (5^2 = 25, 5^4 = 31, so 5^7 = 31 * 25 * 5 mod 33 = 14). Decrypt: c^d = 14^3 mod 33 = 5. The message comes back as 5.

d must satisfy 7 * d = 1 (mod 20), and 7 * 3 = 21 = 20 + 1, so d = 3. Raising 5 to the public exponent 7 mod 33 gives 14, and raising 14 to the private exponent 3 mod 33 returns 5, closing the key generation, encryption, decryption cycle.

How the result is produced

1

Key generation

The tool multiplies the two primes into n, then computes the Euler totient as (p-1)(q-1). You supply e, and it checks gcd(e, totient) = 1; if e shares a factor with the totient, no modular inverse exists and the choice is rejected. Otherwise the extended Euclidean algorithm finds d with e * d = 1 (mod totient), and the public key (n, e) and private key (n, d) are displayed.

2

Encrypting and decrypting

Encryption is c = m^e mod n, decryption is m = c^d mod n. Instead of computing a huge power directly, the trace shows modular exponentiation step by step: successive squares of the base are reduced mod n and multiplied in according to the bits of the exponent. With p = 3, q = 11 you watch 5^7 mod 33 build from 5^2 = 25 and 5^4 = 31, then reduce 31 * 25 * 5 to 14.

Good uses

  • Verifying a textbook example: trace one full key generation and encrypt/decrypt cycle to find where your own hand arithmetic drifted.
  • Exam or assignment prep in a cryptography course, to internalize where n, the totient, and the inverse come from instead of memorizing formulas.
  • Teaching a class or a curious colleague: walk through the trace on a projector to show why m^e mod n followed by c^d mod n returns the original message.

Limits and checks

  • The primes are tiny, so there is no security. Anyone can factor n and recover d, so these numbers would not survive even casual brute force. Use the tool to understand the algorithm, never to protect data.
  • The plaintext must be strictly less than n. With n = 33, a message of 40 behaves as 40 mod 33 = 7: the ciphertext depends only on that remainder, so decryption returns 7, not 40. Real RSA chops messages into blocks and pads them before encryption precisely for this reason.
  • d is only defined modulo the totient. Some sources compute the inverse modulo Carmichael's lambda, lcm(p-1, q-1), instead, so a d you see elsewhere can differ from the tool's d and still decrypt correctly, because lambda divides the totient.

Common questions

I entered a message and it did not decrypt back to what I typed. What went wrong?

Almost always the message is not smaller than n, so the ciphertext depends only on its remainder modulo n and decryption returns that remainder, not the value you typed. Try a value between 0 and n-1, or pick larger primes. Real systems avoid this by splitting the message into blocks and applying padding before encryption; this tool applies no padding, so the constraint is yours to respect.

Is this how real RSA works? Can I use these numbers to encrypt something?

The math is the real RSA math, but production RSA uses moduli of 2048 bits or more plus padding such as OAEP (PKCS #1), because unpadded textbook RSA leaks information and is vulnerable. The sizes here exist for legibility. For actual encryption, use a cryptographic library rather than any numbers you compute here.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools