When primes share a secret

Why a shared factor is enough to unravel two toy RSA moduli.

The challenge

This toy exercise uses tiny integers to illustrate a key-generation failure. The numbers are intentionally unsuitable for real cryptographic use.

The shared factor

If two moduli reuse a prime pp, their greatest common divisor reveals that shared factor:

n1=pq1,n2=pq2n_1 = p q_1, \qquad n_2 = p q_2

For distinct primes pp, q1q_1 and q2q_2:

gcd⁡(n1,n2)=p\gcd(n_1, n_2) = p

Reproducing the observation

from math import gcd

n1 = 61 * 53
n2 = 61 * 47
p = gcd(n1, n2)

assert 1 < p < min(n1, n2)
print(p, n1 // p, n2 // p)
61 53 47

Lessons learned

This example demonstrates factor recovery only. A real assessment would separately verify the relevant public keys, algorithm parameters and authorization to test them. Reliable key generation depends on a correctly initialized, cryptographically secure source of randomness.