RSA Calculator

Generate RSA keys and perform encryption/decryption

Usually 65537 (default) or 3. Must be coprime with φ(n).

Enter a number less than n to see encryption/decryption (optional)

How to Use This Calculator

1

Choose Two Prime Numbers

Enter two different prime numbers for p and q. For demonstration, use small primes like 61 and 53. For real security, use much larger primes.

2

Choose Public Exponent

Enter a public exponent e (typically 65537 or 3). It must be coprime with φ(n) = (p-1)(q-1).

3

Generate Keys

Click Calculate to generate the public and private key pairs. The calculator will show n, φ(n), and the private exponent d.

4

Encrypt/Decrypt (Optional)

Enter a numeric message less than n to see encryption and decryption in action.

Formulas

n = p × q

φ(n) = (p - 1) × (q - 1)

d = e-1 mod φ(n)

Encryption:

c = me mod n

where m is the message, c is ciphertext

Decryption:

m = cd mod n

where c is ciphertext, m is plaintext

About RSA Calculator

RSA (Rivest-Shamir-Adleman) is one of the first public-key cryptosystems and is widely used for secure data transmission. Named after its inventors (Ron Rivest, Adi Shamir, and Leonard Adleman) who published it in 1977, RSA is based on the mathematical difficulty of factoring large integers.

How RSA Works

RSA uses a public key for encryption and a private key for decryption. The security relies on the fact that while it's easy to multiply two large primes, it's computationally infeasible to factor their product back into the original primes.

Key Generation Steps

  1. Choose two distinct prime numbers p and q
  2. Calculate n = p × q (the modulus)
  3. Calculate φ(n) = (p-1)(q-1) (Euler's totient function)
  4. Choose e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1
  5. Calculate d such that d ≡ e-1 (mod φ(n))
  6. Public key is (n, e); Private key is (n, d)

Security

RSA security depends on the difficulty of integer factorization. For real-world applications, p and q should be large primes (typically 1024-4096 bits). Smaller primes are used here only for demonstration and educational purposes.

Applications

  • Digital Signatures: Verify authenticity of messages
  • Secure Communications: HTTPS, SSH, email encryption
  • Key Exchange: Secure establishment of shared secrets
  • Cryptocurrency: Blockchain and wallet security

Frequently Asked Questions

Why are the primes so small in this calculator?

For demonstration and educational purposes, we use small primes so calculations are quick and easy to verify. Real RSA implementations use primes with hundreds or thousands of digits. Using small primes here makes the math visible but is completely insecure for actual use.

What makes RSA secure?

RSA security relies on the difficulty of factoring large composite numbers. Given n = p × q, finding p and q is computationally hard for large primes. However, advances in quantum computing may one day threaten RSA security.

Why is e usually 65537 or 3?

Small exponents like 3 and 65537 make encryption faster. 65537 (2^16 + 1) is a Fermat prime that's large enough to avoid some attacks while still being efficient. It's also commonly coprime with φ(n).

Can I encrypt text messages?

This calculator works with numbers. To encrypt text, you'd first convert each character to a number (e.g., using ASCII), then encrypt each number. Real RSA implementations typically encrypt a symmetric key, not the message directly, due to size and efficiency constraints.

What happens if I use non-prime numbers for p and q?

The calculator will alert you that p and q must be prime. RSA requires primes because the security depends on the difficulty of factoring n. If p or q weren't prime, n would be easier to factor, breaking the security.