Get AI summaries of any video or article — Sign up free
How Shor's Algorithm Factors 314191 thumbnail

How Shor's Algorithm Factors 314191

minutephysics·
4 min read

Based on minutephysics's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

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?

It seeks the period p (the order) of a modulo N. In the transcript’s framing, p is chosen so that a^p is 1 more than a multiple of 314191—equivalently, a^p ≡ 1 (mod 314191). Once p is known, the algorithm can form a^(p/2) ± 1 (when p is even) and use gcd with N to extract nontrivial factors.

How does measuring a remainder after modular exponentiation help reveal the period?

The quantum computation builds a superposition over powers of a (e.g., 101^k) and maps each power to its remainder mod 314191. Measuring a remainder collapses the state to a set of exponents that all produce the same remainder. Those exponents differ by exactly p, so the remaining quantum state contains a periodic structure in the exponent domain.

Why does the quantum Fourier transform matter after the remainder measurement?

Because the periodic spacing by p in the exponent domain becomes a frequency pattern after the quantum Fourier transform. Measuring after the transform yields values from which p can be inferred. The transcript gives an example outcome for a=101 that leads to p=4347, illustrating how the transform converts “periodicity” into measurable structure.

What goes wrong with p=4347 for a=101, and why does that force a restart?

The next classical step needs a^(p/2) to be well-defined as an integer exponent. Since 4347 is odd, p/2 is not an integer, so the algorithm can’t directly compute a^(p/2) ± 1 in the intended way. The procedure therefore picks a new random a and repeats the quantum period-finding step.

How does the transcript extract the final factors once p is even for a=127?

With a=127, the period is reported as p=17388 (even). The algorithm computes 127^(p/2) = 127^8694, then applies Euclid’s algorithm to gcd(314191, 127^8694 + 1) and gcd(314191, 127^8694 − 1). The results are 829 and 379, and multiplying them gives 314191.

What concrete check confirms the factorization is correct?

The transcript verifies that 829 × 379 equals 314191. It also notes that 101^4347 is exactly 1 more than a multiple of 314191, confirming the period-finding step for the first attempt even though the oddness of p prevented factor extraction.

Review Questions

  1. In Shor’s algorithm, what relationship between a^p and N makes the period p useful for factoring?
  2. Why does an odd period p (like 4347) prevent the straightforward gcd step, and what does the algorithm do instead?
  3. For the successful run with a=127, which two gcd computations produce the factors, and what are the resulting factors?

Key Points

  1. 1

    Shor’s algorithm factors N=314191 by first finding the order p of a modulo N using quantum period-finding.

  2. 2

    Modular exponentiation in superposition maps powers of a to remainders mod 314191; measuring a remainder leaves exponents spaced by p.

  3. 3

    Applying the quantum Fourier transform converts that exponent periodicity into measurable outcomes that reveal p.

  4. 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. 5

    With a=127, the period is p=17388; then gcd(314191, 127^8694 ± 1) yields factors 829 and 379.

  6. 6

    The factorization is confirmed by 829 × 379 = 314191, demonstrating the quantum-to-classical pipeline behind Shor’s method.

Highlights

For a=101, the period-finding step yields p=4347, and 101^4347 is exactly 1 more than a multiple of 314191—yet factor extraction fails because p is odd.
The quantum Fourier transform is the mechanism that turns “spacing by p” into a frequency pattern from which p can be inferred.
Restarting with a different a is not a side detail; it’s necessary when the first period is odd.
With a=127 and p=17388, Euclid’s algorithm on gcd(314191, 127^8694 ± 1) produces 829 and 379.
The final check is arithmetic: 829 × 379 reconstructs 314191.

Topics

  • Shor’s Algorithm
  • Quantum Period Finding
  • Modular Exponentiation
  • Quantum Fourier Transform
  • Integer Factorization

Mentioned