Roots of Unity mod N (Non-Trivial Roots Reveal Factors)
- •
What it is
- •
An -th root of unity modulo is any value satisfying . Modulo a prime, the only square roots of unity are — a direct consequence of having at most 2 roots in a field. Modulo a composite , though, the Chinese Remainder Theorem guarantees four square roots of unity exist (one combination of and each) — meaning a value with can exist, and finding one is exactly as good as factoring : splits off a genuine, non-trivial factor immediately. This single fact is the shared mechanism behind Miller-Rabin's ability to detect composite numbers, the classic "factor N given a known (e,d) pair" algorithm, and RSA's "unconcealed message" fixed-point weakness — all three reduce to "find a non-trivial square root of unity mod N," just arriving at the search differently.
- •
- •
When to apply
- •
Any time you have (or can construct) a value with known order dividing some power of 2 modulo an unfactored composite — repeatedly squaring down from that value and checking at each step is the standard way to convert that knowledge directly into a factorization.
- •
- •
Symbols and assumptions
- •
with distinct odd primes. A square root of unity is an satisfying . The roots are called trivial here.
- •
- •
Math — step by step
- •
- •
Python
- •
from math import gcd x = starting_value # known to have order dividing some power of 2, mod N for _ in range(30): x = pow(x, 2, N) g = gcd(x - 1, N) if 1 < g < N: p, q = g, N // g break
- •
- •
- •
Cards
- •
How many square roots of unity does a composite N=pq have, versus a prime modulus?
- •
Exactly 4, versus only 2 (±1) for a prime modulus — the extra two "non-trivial" roots only exist because N is composite.
- •
- •
Why does finding a non-trivial square root of unity mod N immediately give you a factor?
- •
gcd(x-1, N) evaluates to exactly one of N's two prime factors, since x agrees with +1 modulo one factor and -1 modulo the other.
- •
- •