Our public key is:
(e, n) = (7, 143)Suppose that is all an attacker receives. Can the private key be recovered?
With our 8-bit RSA example, yes, almost immediately.
Important: This attack is demonstrated against a deliberately tiny educational key. It illustrates why real RSA depends on a modulus that is computationally infeasible to factor with known classical techniques.
3.1 Factor the Public Modulus#
The attacker knows: n = 143
Factor it:
143 = 11 * 13Therefore the supposedly secret primes have been recovered:
p = 11
q = 133.2 Reconstruct phi(n)#
phi(n) = (p - 1)(q - 1)
= 10 * 12
= 1203.3 Recover the Private Exponent#
The public exponent is known: e = 7
Find its modular inverse modulo 120:
d = 7^-1 mod 120
= 103Check:
7 * 103 = 721
721 mod 120 = 1The private key is now reconstructed:
(d, n) = (103, 143)Python: Crack our toy key#
The following deliberately simple script starts with only the public key:
# Educational attack against our tiny RSA key
# Information available to the attacker
e = 7
n = 143
print("Public key:", (e, n))
# Factor n using simple trial division
for candidate in range(2, n):
if n % candidate == 0:
p = candidate
q = n // candidate
break
print("Found p:", p)
print("Found q:", q)
# Reconstruct phi(n)
phi = (p - 1) * (q - 1)
print("phi(n):", phi)
# Recover the private exponent
d = pow(e, -1, phi)
print("Recovered d:", d)
print("Recovered private key:", (d, n))Expected output:
Public key: (7, 143)
Found p: 11
Found q: 13
phi(n): 120
Recovered d: 103
Recovered private key: (103, 143)📌 The Attack#
Public key
(7,143)
|
| factor n
v
143 = 11 * 13
|
v
p=11, q=13
|
v
phi(n)=120
|
| d = e^-1 mod phi(n)
v
d = 103
|
v
Private key recovered
(103,143)🔑 The central RSA lesson#
A useful mental model is:
public n
|
| difficult direction
v
recover p and q
|
v
calculate phi(n)
|
v
calculate d
|
v
recover private keyFor our tiny modulus, factoring is trivial.
Secure RSA makes the modulus large enough that recovering its carefully generated prime factors is computationally infeasible with known classical methods.
We normally do not think of the attack as blindly guessing d.
Factoring n is the important mathematical route illustrated here.
In Part 4, we scale this intuition from our 8-bit toy key to RSA-2048 and look at why prime size and balance matter.


