RSA Calculator

Toy RSA Key Calculator

Demonstrate RSA arithmetic for small classroom examples by calculating the modulus, totient, and private exponent.

Educational only, not for real cryptography. This toy calculator validates small prime inputs and demonstrates the RSA arithmetic. It does not generate secure random primes, protect secret values, or produce production-ready keys. Use a vetted cryptographic library for real encryption or authentication.

Last updated: March 2026 | Cryptography Tool (Educational)

RSA Key Parameters

What is RSA Encryption?

RSA (Rivest–Shamir–Adleman) is one of the most widely used asymmetric (public-key) encryption algorithms. It's based on the mathematical difficulty of factoring large integers into their prime factors. RSA uses two keys: a public key for encryption and a private key for decryption.

The security of RSA depends on the difficulty of determining the private key from the public key. The larger the key size (typically 2048 or 4096 bits), the harder it is to crack. This calculator uses small primes for educational purposes and should never be used for actual security applications.

How RSA Key Generation Works

  1. Choose two distinct large primes: p and q
  2. Calculate n: n = p × q (the modulus)
  3. Calculate φ(n): φ(n) = (p-1) × (q-1) (Euler's totient)
  4. Choose e: where 1 < e < φ(n) and gcd(e, φ(n)) = 1
  5. Calculate d: where e × d ≡ 1 (mod φ(n))
  6. Public Key: (e, n)
  7. Private Key: (d, n)

Frequently Asked Questions

Why does RSA use two large primes?

The security of RSA relies on the difficulty of factoring n back into its prime factors p and q. With large primes (hundreds of digits), this factorization is computationally infeasible even for modern computers. Finding the prime factors is the "hard problem" that protects the key.

What is Euler's totient function φ(n)?

φ(n) counts how many integers from 1 to n are coprime with n (share no common factors). For two distinct primes p and q: φ(n) = (p-1)(q-1). This function is critical to RSA key generation and ensures the mathematical properties needed for encryption.

Why must gcd(e, φ(n)) = 1?

For encryption and decryption to be inverse operations, e and φ(n) must be coprime (share no common factors). If gcd(e, φ(n)) ≠ 1, then a unique modular inverse d doesn't exist, and the decryption won't work. This is a requirement of modular arithmetic.

Should I use small primes like in this calculator?

Absolutely not for real applications. This calculator is educational only. Real-world RSA uses 2048-bit or 4096-bit keys (primes with 600+ digits). Small keys like these examples are trivially breakable—modern computers can factor them in seconds.

What's a common choice for the public exponent e?", a: "The most common choice is e = 65537 (0x10001 in hex). It's a large prime that's been standardized, has only two 1-bits in binary (efficient for computation), and has no known weaknesses. For this calculator, we accept any e coprime to φ(n)." }, { q: "How do I use the public and private keys?", a: "Public key (n, e): Publicly shared. Anyone can use it to encrypt messages. Private key (n, d): Keep secret. Only you can decrypt messages. To encrypt: C = M^e mod n. To decrypt: M = C^d mod n. Never share d!" }, { q: "What happens if someone knows p or q?", a: "If either prime factor is revealed, an attacker can compute φ(n) = (p-1)(q-1), then compute d from e, and decrypt all messages. This is why keeping p and q secret after key generation is critical, and why factoring large numbers is so hard." }, { q: "Is RSA still secure today?", a: "Yes, with proper key sizes (2048+ bits). The underlying math is sound—no known weaknesses exist. However, 1024-bit keys are considered breakable. Quantum computers may threaten RSA in the future, prompting research into post-quantum cryptography."

Related Tools