RSA Encryption Calculator

Generate RSA keys from two prime numbers, then encrypt and decrypt a message with step-by-step explanation.

RSA Key Generation & Encryption

A small prime number
A different small prime
Must be coprime with phi(n). Leave default or choose your own.
A number to encrypt (must be less than n = p * q)

Result

Encrypted Message (Ciphertext)
--
Decrypted Message (Verified)
--
n = p * q--
phi(n) = (p-1)(q-1)--
Public Key (e, n)--
Private Key (d, n)--

Step-by-Step Solution

What is RSA Encryption?

RSA (Rivest-Shamir-Adleman) is one of the first public-key cryptosystems and is widely used for secure data transmission. It relies on the mathematical difficulty of factoring the product of two large prime numbers. RSA involves a public key (for encryption) and a private key (for decryption).

How RSA Works

1. Key Generation

Choose two primes p and q. Compute n = p*q and phi(n) = (p-1)(q-1). Choose e coprime with phi(n), find d such that e*d = 1 mod phi(n).

n = p * q, d = e^(-1) mod phi

2. Encryption

Convert the message to a number m. Compute ciphertext c = m^e mod n using the public key.

c = m^e mod n

3. Decryption

Compute original message m = c^d mod n using the private key.

m = c^d mod n

Security of RSA

The security of RSA relies on the practical difficulty of factoring the product of two large prime numbers. In real-world applications, RSA typically uses key sizes of 2048 or 4096 bits. This calculator uses small primes for demonstration purposes only.

Important Concepts

  • Euler's Totient Function: phi(n) counts integers less than n that are coprime with n.
  • Modular Exponentiation: Efficiently computing large powers modulo n.
  • Extended Euclidean Algorithm: Used to find the modular inverse d of e.
  • Coprime: Two numbers are coprime if their GCD is 1.