Skip to content
100% local

RSA cipher

Encrypt and decrypt numbers with RSA, including generating a key pair from two primes.

Input
Output

RSA cipher

This tool runs RSA, the public-key algorithm behind HTTPS and PGP, entirely in your browser. Pick a key size and it builds a key pair from two primes chosen behind the scenes, or type in your own values for p and q to see exactly how the math works. Paste text, hex or Base64 into the box, choose encrypt or decrypt, and the result updates as you type.

Under the hood, every byte of the input is raised to the public exponent e modulo n to encrypt it, and to the private exponent d modulo n to decrypt it — the same operation the classic p=61, q=53 textbook example uses, just automated. The key size preset picks two primes for you; the "Prime p" and "Prime q" fields let you override that, and the tool checks that your values are genuinely prime, distinct and large enough first. Plaintext format controls how the input (or decrypted output) is read — as text, hex or Base64 — while ciphertext format controls how the encrypted result is written, in hex or Base64. There is no salt or iteration count here, because RSA doesn't use either — it's a direct operation on numbers derived from the primes, not a password-based scheme.

Switch the mode to swap encrypt for decrypt and the tool tries to reverse the last result with the same key. Because these keys are small enough to compute instantly in a browser tab, they're for learning how RSA works, not for protecting anything real — use the site's encrypt-text tool (AES-256-GCM) for that. The "compare to expected value" field checks your result against a known answer, handy when following a textbook example.

Everything runs locally: no keys, primes or text are ever sent anywhere. Copy the result, download it as a .txt file, or send the output straight back into the input to chain another step.

FAQ

Is this safe to use for real encryption?
No. The key sizes here (tens of bits) are chosen to compute instantly in a browser and are trivial to break — real RSA needs 2048-bit keys or larger with proper padding. This tool is for learning how the algorithm works. For genuinely private text, use the encrypt-text tool instead.
Where do the primes come from if I don't enter my own?
Each key size preset uses a fixed pair of primes computed once, so the same preset always gives the same key — useful for reproducible examples. Enter your own values in the Prime p / Prime q fields to use different ones.
Why do the primes have to be larger than a certain size?
Each plaintext byte (0–255) must be smaller than the modulus n = p × q for the math to work, so n has to exceed 255. The tool rejects prime pairs that are too small, and rejects 2 as a prime here specifically, since RSA needs both primes odd for every byte to encrypt correctly.
What happens if I decrypt with the wrong key?
You'll get an error rather than garbled output — the tool checks that every decrypted block is a valid byte (0–255) under the key you supplied, and reports a mismatch instead of silently returning nonsense.
Is my text or my primes uploaded anywhere?
No. Key generation and every encryption or decryption runs entirely in your browser — nothing you type is sent to a server.