What is RSA?
Key Concepts and Terminology
RSA Algorithm Steps
The most important part. You create the public and private keys here.
Choose two large prime numbers: $p$ and $q$
These should be large (hundreds of digits) and randomly chosen.
Calculate $n = p \times q$
$n$ will be used as part of both the public and private keys. It is the modulus for encryption and decryption.
Calculate Euler’s Totient $\varphi(n) = (p - 1)(q - 1)$
This value is used to determine the public and private exponents.
Choose public exponent $e$ such that:
Common choice: $e = 65537$, because it’s a prime and efficient for computation.
Calculate private exponent dd as the modular inverse of $e$ modulo $\varphi(n)$:
$$ d \equiv e^{-1} \mod \varphi(n) $$
This means:
$$ (d \times e) \mod \varphi(n) = 1 $$
Public key = $(n, e)$
Private key = $(n, d)$
Why Does RSA Work?
This relies on the mathematical property of modular exponentiation and Euler's theorem:
$$ M^{\varphi(n)} \equiv 1 \mod n \quad \text{for } M \text{ coprime with } n $$
Because dd is chosen such that $d \times e \equiv 1 \mod \varphi(n)$, raising M to the power of e and then dd modulo nn gets back the original M.
Security of RSA
RSA algorithm step-by-step with the primes:
Step 1: Calculate $n = p \times q$
$$ n = 13 \times 11 = 143 $$
Step 2: Calculate Euler's Totient $\varphi(n)$
$$ \varphi(n) = (p-1)(q-1) = (13-1)(11-1) = 12 \times 10 = 120 $$
Step 3: Choose the public exponent $e$
$e$ must satisfy:
Explanation:
Commonly used $e$ is 17, but let's check if 17 works:
gcd(17, 120) = 1 → valid.
So,
$$ e = 17 $$
Step 4: Calculate the private exponent $d$