# RSA Calculator

Explore RSA encryption and decryption with small primes. See how public/private keys are generated and how messages are encrypted and decrypted.

## What this calculates

Explore how RSA encryption works using small prime numbers. This educational calculator generates public and private keys, encrypts a message, and decrypts it back to demonstrate the complete RSA process.

## Inputs

- **Prime p** — min 2 — First prime number. Keep small for demonstration (under 1000).
- **Prime q** — min 2 — Second prime number, different from p. Keep small for demonstration.
- **Message (integer m)** — min 0 — The plaintext message as a number. Must be less than n = p x q.

## Outputs

- **n = p x q (modulus)** — The RSA modulus, part of both the public and private keys.
- **phi(n) = (p-1)(q-1)** — Euler's totient of n, used to compute the keys.
- **Public exponent e** — The public encryption exponent. Coprime to phi(n); commonly 65537 or smaller.
- **Private exponent d** — The private decryption exponent. Satisfies e x d = 1 (mod phi(n)).
- **Encrypted message (ciphertext)** — formatted as text — The ciphertext: c = m^e mod n.
- **Decrypted message** — formatted as text — Decryption of the ciphertext: m = c^d mod n.

## Details

RSA (Rivest-Shamir-Adleman) is one of the first public-key cryptosystems and is widely used for secure data transmission. This calculator demonstrates the algorithm with small numbers so you can see every step.

How RSA Works

- Choose two primes p and q. Compute n = p x q.

- Compute Euler's totient: phi(n) = (p-1)(q-1).

- Choose public exponent e such that 1 < e < phi(n) and gcd(e, phi(n)) = 1. The value 65537 is a common choice.

- Compute private exponent d such that e x d = 1 (mod phi(n)).

- Encrypt: ciphertext c = m^e mod n.

- Decrypt: plaintext m = c^d mod n.

Why It Works

The security relies on the difficulty of factoring n back into p and q. Multiplying two primes is fast, but reversing that multiplication (factoring) is computationally hard for very large numbers. Real RSA uses primes with hundreds of digits.

Important Note

This calculator uses small numbers for educational purposes. Real RSA implementations use 2048-bit or larger keys, which involve primes with over 300 digits each.

## Frequently Asked Questions

**Q: What is RSA encryption?**

A: RSA is a public-key cryptographic algorithm where encryption uses a public key (n, e) and decryption uses a private key (n, d). Anyone can encrypt a message with the public key, but only the holder of the private key can decrypt it. The security depends on the difficulty of factoring the product of two large primes.

**Q: Why do p and q need to be prime?**

A: RSA relies on Euler's totient function, which has a simple formula when n is a product of two distinct primes: phi(n) = (p-1)(q-1). If p or q were not prime, the totient calculation would be different and the key generation process would not work correctly. The primes must also be kept secret.

**Q: Is this calculator secure for real encryption?**

A: No. This calculator is for learning only. Real RSA uses primes with hundreds of digits (2048-bit keys or larger). The small numbers used here can be factored instantly. Never use small primes for actual encryption. Use established libraries like OpenSSL for real cryptographic needs.

**Q: What is the public exponent e = 65537?**

A: 65537 (which is 2^16 + 1) is the most commonly used public exponent in real RSA implementations. It is a Fermat prime, which makes encryption fast due to its binary representation (only two 1-bits). It is large enough to be secure against certain attacks while remaining efficient for computation.

---

Source: https://vastcalc.com/calculators/technology/rsa
Category: Technology
Last updated: 2026-04-21
