Recursive RSA-Style Factorization via Known φ(N) (Multi-Prime Moduli)
- •
What it is
- •
A generalization of the "factor N from a known (N,e,d) triple" trick to moduli built from more than two prime factors. If you know and its exact Euler totient (not just an key pair), you can pick any exponent coprime to , compute a matching , and run the same probabilistic "non-trivial square root of unity" factoring algorithm — it will split into two non-trivial factors, but if has more than two prime factors, at least one piece will still be composite. Recursing — checking primality of each resulting factor and re-splitting any that aren't prime yet, reusing the same pair — fully factors into all of its prime components, regardless of how many there are.
- •
- •
When to apply
- •
A challenge directly hands you both and (rather than making you factor from scratch), and is explicitly stated (or suspected) to be a product of more than two primes.
- •
- •
Math
- •
Same core mechanism as RSA Factorization from Known (N, e, d) — for any coprime to and , is a multiple of , letting the randomized square-root-of-unity search split ; since of any product of a subset of 's prime factors still divides (each divides ), the exact same pair remains valid for splitting any composite sub-factor recursively.
- •
- •
Worked example
- •
A toy modulus built from 5 distinct 48-bit primes, given only : picking and deriving , then recursively applying the standard factor-from- split (checking primality at each step and re-splitting composite results with the same ) recovered all 5 original prime factors exactly.
- •
- •
Python
- •
def recursive_factor(n, e, d): factors = [] stack = [n] while stack: cur = stack.pop() if is_prime(cur): factors.append(cur) continue p, q = factor_from_d(cur, e, d) # same routine as the 2-factor case stack.extend([p, q]) return factors
- •
- •
SageMath
- •
PyCryptodome's
RSA.construct([n, e, d], consistency_check=False)conveniently exposes this splitting step directly as.p/.qattributes (it computes them internally using this exact algorithm) — a nice shortcut if working in Python with that library already available, rather than hand-rolling the search.
- •
- •
- •
Cards
- •
Why does the same (e,d) pair remain valid for splitting a composite sub-factor of N, not just N itself?
- •
φ of any product of a subset of N's prime factors still divides φ(N) (each (p_i - 1) divides φ(N)), so ed-1 remains a multiple of that sub-factor's totient too.
- •
- •
What extra step does this technique need beyond the basic two-factor version?
- •
Recursion: check whether each split-off piece is actually prime, and if not, re-run the same splitting routine on it.
- •
- •