๐Ÿ” RSA Encryption Demo

An educational demo using small numbers. Not suitable for real security.

n = p ร— q33
ฯ†(n) = (p-1)(q-1)20
Private exponent (d)3
Ciphertext (c = m^e mod n)29
Decrypted (c^d mod n)2
โœ“ The decrypted result matches the original message

Enter small primes p and q, a public exponent e, and a message (a number) to see how RSA generates keys (n, ฯ†(n), private exponent d), encrypts, and decrypts โ€” step by step.

How to use

  1. Enter two distinct primes p and q.
  2. Enter a public exponent e (must be coprime to ฯ†(n)).
  3. Enter the message to encrypt (an integer less than n).
  4. n, ฯ†(n), the private exponent d, the ciphertext, and the decrypted result are calculated automatically.

How the calculation works

RSA, published by Rivest, Shamir and Adleman in 1977, is a public-key cryptosystem whose security rests on the difficulty of factoring large numbers. This tool builds keys from small primes and walks through encryption and decryption. 1. Choose two primes p and q and compute n = p ร— q. 2. Compute ฯ†(n) = (p โˆ’ 1)(q โˆ’ 1). 3. Choose a public exponent e that is coprime with ฯ†(n). 4. Find the private exponent d with e ร— d โ‰ก 1 (mod ฯ†(n)). The public key is (n, e) and the private key is d. A message m (a number smaller than n) is encrypted as c = m^e mod n and decrypted as m = c^d mod n. If e and ฯ†(n) are not coprime, no d exists, and the tool says so.

Worked example

p = 61, q = 53, e = 17, message m = 65 n = 61 ร— 53 = 3233 ฯ†(n) = 60 ร— 52 = 3120 d = 2753 (17 ร— 2753 = 46801 = 15 ร— 3120 + 1) Encrypt: 65ยนโท mod 3233 = 2790 Decrypt: 2790ยฒโทโตยณ mod 3233 = 65 With the defaults (p = 3, q = 11, e = 7, m = 2): n = 33, d = 3, ciphertext 29.

Things to be aware of

  • These keys are tiny, so n can be factored instantly. Real RSA uses an n of 2048 bits or more (over 600 decimal digits).
  • Textbook RSA without padding has weaknesses (the same message always gives the same ciphertext, for example), so real systems use padding schemes such as OAEP.
  • In practice, the public exponent e is usually 65537.

FAQ

What is RSA encryption?

A widely used public-key cryptography algorithm whose security rests on the difficulty of factoring large numbers. It underlies much of HTTPS and other encrypted communication.

Why canโ€™t small numbers be used for real security?

A product (n) of small primes can be factored trivially by brute force or known algorithms. Real RSA uses primes hundreds of digits long.

Can e be any value?

No โ€” e must be coprime to ฯ†(n) (their greatest common divisor must be 1). If it isnโ€™t, no valid private exponent d exists.