RSA with p = q (Repeated Prime Factor)
- •
What it is
- •
If RSA key generation accidentally reuses the same prime for both factors (), the modulus becomes a perfect square, — trivially factored by taking an ordinary integer square root, no specialized factoring algorithm needed at all.
- •
- •
When to apply
- •
Any hint that a "unique" large prime was generated once and reused (source code explicitly doing this, or a modulus that happens to be a perfect square) is worth checking with
isqrt(N)**2 == Nbefore reaching for any real factoring tool.
- •
- •
Math
- •
exactly. — Euler's totient of a prime power, not .
- •
- •
Worked example
- •
Let , , , and . Since and , . Encryption gives and . The standard exponent argument applies to units modulo ; messages divisible by require separate care because exponentiation need not be a permutation on those non-units.
- •
- •
Python
- •
from math import isqrt p = isqrt(N) assert p * p == N phi = p * (p - 1) d = pow(e, -1, phi)
- •
- •
Related
- •