GenerateRandomSearch

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

  1. Pick two different small primes.
  2. Choose a public exponent; an unusable one is replaced and the page says so.
  3. Enter a message smaller than the modulus.
  4. 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.

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.