How Shor's Algorithm Factors 314191
Based on minutephysics's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
Shor’s algorithm factors N=314191 by first finding the order p of a modulo N using quantum period-finding.
Briefing
Shor’s algorithm can factor a specific “encryption key” number—314191—by using a quantum computer to find the hidden period that makes modular exponentiation line up. The practical payoff is immediate: once the period p is recovered, classical number theory (Euclid’s algorithm) turns that information into the actual prime factors, which then multiply back to 314191.
The walkthrough starts with the standard Shor setup: pick a random guess a that is coprime to N=314191 (the transcript uses 101 first). The quantum part targets the order p of a modulo N, defined so that a^p is 1 more than a multiple of N (or, more generally, congruent to 1 mod N). To get p, the computation prepares a superposition of powers of a, effectively mapping states to remainders of a^k mod N. Measuring the remainder collapses the system to a single remainder value—an example remainder given is 74126—leaving the remaining quantum state in a superposition of exponents that differ by exactly p.
With that periodic structure in hand, the next step applies the quantum Fourier transform, which converts the “spacing by p” in the exponent domain into a frequency pattern in the measurement outcomes. After measuring again, the result is a value that lets the period be inferred. For the specific choice a=101, the transcript reports that the period comes out as p=4347, and it verifies the key congruence by noting that 101^4347 is exactly 1 more than a multiple of 314191 (the multiple is enormous, but the modular relationship is exact).
From p, Shor’s algorithm produces a candidate factor by computing gcd(a^(p/2) ± 1, N). But there’s a catch: 4347 is odd, so p/2 is not an integer, forcing the procedure to restart with a different random guess. The transcript then switches to a=127 and repeats the same quantum period-finding routine. This time the period is reported as p=17388, which is even, so the algorithm can form a^(p/2) = 127^8694.
Finally, Euclid’s algorithm is applied to gcd(314191, 127^8694 + 1) and gcd(314191, 127^8694 − 1). The results are 829 and 379, and their product returns the original number: 829 × 379 = 314191. That completes the factorization, demonstrating how Shor’s method turns quantum periodicity into concrete factors—exactly the kind of capability that threatens RSA-style encryption when scaled to larger keys.
The segment closes with a practical security plug: using a password manager (Dashlane) to generate and store long, unique passwords, plus monitoring for weak passwords and breaches, and offering additional features like a VPN.
Cornell Notes
Shor’s algorithm factors N=314191 by finding the order p of a chosen number a modulo N. The quantum computer creates a superposition of a^k values, measures remainders, and uses the quantum Fourier transform to extract the period p from the resulting frequency structure. For a=101, the period is found to be p=4347, but it fails the next step because p is odd, so the method restarts. With a=127, the period becomes p=17388; then gcd(314191, 127^8694 ± 1) yields factors 829 and 379, whose product equals 314191. This links quantum periodicity directly to classical gcd computations that produce the factorization.
What does Shor’s algorithm try to find when factoring N=314191, and how is p defined?
How does measuring a remainder after modular exponentiation help reveal the period?
Why does the quantum Fourier transform matter after the remainder measurement?
What goes wrong with p=4347 for a=101, and why does that force a restart?
How does the transcript extract the final factors once p is even for a=127?
What concrete check confirms the factorization is correct?
Review Questions
- In Shor’s algorithm, what relationship between a^p and N makes the period p useful for factoring?
- Why does an odd period p (like 4347) prevent the straightforward gcd step, and what does the algorithm do instead?
- For the successful run with a=127, which two gcd computations produce the factors, and what are the resulting factors?
Key Points
- 1
Shor’s algorithm factors N=314191 by first finding the order p of a modulo N using quantum period-finding.
- 2
Modular exponentiation in superposition maps powers of a to remainders mod 314191; measuring a remainder leaves exponents spaced by p.
- 3
Applying the quantum Fourier transform converts that exponent periodicity into measurable outcomes that reveal p.
- 4
If p is odd (as with p=4347 for a=101), the algorithm can’t form a^(p/2) as an integer and must restart with a different a.
- 5
With a=127, the period is p=17388; then gcd(314191, 127^8694 ± 1) yields factors 829 and 379.
- 6
The factorization is confirmed by 829 × 379 = 314191, demonstrating the quantum-to-classical pipeline behind Shor’s method.