RSA is normally discussed with 2048-bit or larger keys.
Those numbers are appropriate for real security, but they make the underlying mathematics difficult to see.
So this series starts with a deliberately insecure RSA key small enough to calculate by hand.
Important: Everything in this series is for learning.
1.1 Choose 2 Primes#
First, Let choose 2 primes, p and q:
p = 11
q = 13RSA does not require q > p.
Swapping them changes nothing because multiplication is commutative.
The primes should, however, be different in normal RSA: p != q.
1.2 Calculate the Modulus#
n = p * q
= 11 * 13
= 143143 in binary is:
10001111Therefore n has a bit length of 8.
This is our toy 8-bit RSA example.
When people say RSA-2048, the 2048 normally refers to the approximate bit length of the modulus n, not the bit length of each prime.
1.3 Calculate Euler’s totient#
Since p and q are distinct primes:
phi(n) = (p - 1)(q - 1)
= 10 * 12
= 1201.4 Choose the Public Exponent#
To form the public key (e,n), we need to choose an e.
Choose e where 1 < e < phi(n):
e = 7And it must be relatively prime to phi(n):
gcd(7, 120) = 1How is it choosen
e is a free choice from a pool of valid candidates: any integer between 2 and 119 that shares no factors with 120.
Other valid choices for phi(n) = 120 include: 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49.
Our public key is now:
(e, n) = (7, 143)1.5 Calculate the Private Exponent#
We need d such that: e * d = 1 mod phi(n)
Resolve our values:
7 * d = 1 mod 120The answer is:
d = 103because:
7 * 103 = 721
721 mod 120 = 1Therefore:
Public key = (7, 143)
Private key = (103, 143)📌 Story Board#
p = 11 q = 13
\ /
\ /
+---- multiply ----+
|
v
n = 143
|
phi(n) = 120
|
+-----+-----+
| |
v v
e = 7 d = 103
| |
v v
Public key Private key
(7,143) (103,143)🔑 Key Takeaway#
- RSA begins with two secret primes,
pandq. - The public modulus is
n = p * q. - The public key contains
eandn. - The private exponent
dis mathematically related toethrough the factors ofn. - Real RSA uses vastly larger values, but the basic idea is the same.
In Part 2, we will use the key to encrypt and decrypt a number and implement the whole exercise in Python.


