Toy RSA Key Generator
RSA is easier to believe once you have watched a message go in one end and come back out the other with numbers small enough to check on paper. This builds a key from two primes you pick, encrypts a message, decrypts it again, and then verifies the round trip for every message the modulus can carry — not just the one you chose. These parameters are far too small to protect anything and are chosen so the arithmetic can be followed by hand. This is a teaching demonstration, not a security tool — real work belongs in a reviewed cryptographic library.
What this generator does
Multiplies two primes for the modulus, computes the totient, finds a usable public exponent and its inverse, and encrypts and decrypts your message. Every message in the modulus is then round-tripped as a check.
How to use this tool
- Pick two different small primes.
- Choose a public exponent; an unusable one is replaced and the page says so.
- Enter a message smaller than the modulus.
- Check that decrypting the ciphertext returns your message.
Understanding the controls
- Two primes
- Different small primes. Their product is the modulus, and anyone who factors it back recovers the private key immediately — which at this size takes no time at all.
- Public exponent
- Must share no factor with the totient, or it has no inverse and could never decrypt. If yours does, the next usable one is taken and the page says which.
- Message
- A number smaller than the modulus, since RSA works on numbers modulo it rather than on text.
Worked examples
- The page's own starting numbers
- Primes 17 and 19 give a modulus of 323 and a totient of 288. With public exponent 7, the private exponent works out to 247. Encrypting the default message 42 gives ciphertext 253, and raising 253 to the power 247 modulo 323 returns 42 exactly.
Common use cases
- Following RSA encryption and decryption with real numbers
- Teaching why the private exponent depends on the totient
- Showing that factoring the modulus breaks the key immediately
- Producing worked examples for a cryptography course
- Checking an RSA implementation on numbers you can verify
How this generator works
The modulus is the product of the two primes and the totient is the product of each minus one. The public exponent must be coprime to the totient so that it has a modular inverse, and that inverse is the private exponent. Encrypting raises the message to the public exponent modulo the modulus; decrypting raises the result to the private exponent, and the two operations undo each other because of Euler's theorem. Before display every message from zero up to the modulus is encrypted and decrypted and must come back unchanged.
Randomness and fairness
Nothing here is random — the primes and exponent determine the key. Real RSA generates large random primes, and a key generated this way protects nothing. These parameters are far too small to protect anything and are chosen so the arithmetic can be followed by hand. This is a teaching demonstration, not a security tool — real work belongs in a reviewed cryptographic library.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- The primes are tiny, so the modulus factors instantly and the private key follows — this is a demonstration of the arithmetic, nothing more.
- No padding scheme is applied, and textbook RSA without padding is insecure even at real key sizes.
- Messages are numbers rather than text, since converting text safely is its own topic.
- Signing, which reverses the roles of the two exponents, is not covered here.
Privacy and your data
The key and the message are computed in your browser and never transmitted, stored or included in analytics.
Frequently asked questions
- How quickly could someone break this specific key?
- Instantly — 323 factors as 17 x 19 by trial division in a fraction of a second, which immediately gives the totient and the private exponent. Real RSA keys use primes hundreds of digits long specifically because factoring a number that size is the hard problem the whole scheme rests on; at 17 and 19 there is no hard problem left to solve.
- What happens if I pick a public exponent that shares a factor with the totient?
- It has no modular inverse, so there's no matching private exponent that could ever decrypt anything — the page replaces it with the next usable exponent and says so, rather than producing a key that silently doesn't work.
Related generators
- Diffie-Hellman Exchange GeneratorWalks through a key exchange with numbers small enough to check by hand, confirming both sides reach the same value without sending a secret.
- Secret Sharing GeneratorSplits a number into shares where any threshold of them rebuilds it — checked by trying every combination — and fewer reveal nothing.
- Hamming Code GeneratorEncodes four bits as seven, flips one on purpose, and shows the syndrome pointing straight at the corrupted position.
- Modular Arithmetic Question GeneratorRemainders, modular powers by repeated squaring, and inverses that only exist when the values are coprime.