Shor's Algorithm: Factoring Semi-Primes and Breaking RSA

Introduction to Shor's Algorithm

  • Purpose: Shor's algorithm is designed to factor numbers of the form n=pqn = pq, specifically semi-primes.

  • Significance: Semi-primes are critical for the security of the RSA cryptosystem, making Shor's algorithm a direct threat to current internet security if large-scale quantum computers are built.

  • Classical Factoring Limitations: Prior best-known classical algorithms (e.g., trial division, Pollard's Rho) for factorinlutg a large number nn (product of two primes) are exponential or at least super-polynomial in the size of nn (where size m=log⁡2nm = \log_2 n represents the number of bits of nn).

  • Quantum Advantage: Shor's algorithm on a quantum computer can solve this factoring problem in approximately O(m3)O(m^3) time. This stark difference means RSA is vulnerable to sufficiently large quantum computers.

  • Algorithmic Paradigm: Shor's algorithm implements concepts like divide and conquer on a quantum computer, with the core operation being the Quantum Fourier Transform (QFT).

  • Quantum Fourier Transform (QFT): This is the quantum analogue of the classical Fast Fourier Transform (FFT) and is central to Shor's algorithm. It was studied earlier in the course sequence (part of course three).

High-Level Steps of Shor's Algorithm

  • Conversion to Order Finding: Shor's algorithm transforms the factoring problem into an order finding problem, which is a version of the discrete logarithm problem.

  • Periodic Function: The algorithm relies on finding the unknown period of a periodic function. Quantum computers are particularly adept at this task.

  • Pioneering Work: While called Shor's algorithm, it incorporates contributions from other works, such as quantum phase estimation by Kitaev.

  • Impact: Shor's algorithm is the first known algorithm to demonstrate an exponential speedup on a quantum computer compared to classical computers for a significant problem, fueling immense interest and research in quantum computing.

  • Post-Quantum Cryptography: The potential threat to RSA has spurred development in post-quantum cryptography, with solutions already being explored as of 2024.

Number Theory Basis (Classical Component)

  • Goal: Given n=pqn = pq, where pp and qq are unknown primes, the objective is to find pp and qq.

  • Step 1: Choose a Random Integer AA:

    • Select a random integer AA such that 1<A<n1 < A < n and GCD(A,n)=1GCD(A, n) = 1.

    • Note: If GCD(A,n)<br>eq1GCD(A, n) <br>eq 1, then AA shares a factor with nn, meaning we would have already found a factor like pp or qq. However, the probability of this happening for a large nn is extremely low.

  • Step 2: Explore Powers of AA Modulo nn:

    • Examine the sequence: A1 mod n,A2 mod n,A3 mod n,ext…A^1 \bmod n, A^2 \bmod n, A^3 \bmod n, ext{…}.

    • Periodicity: Since AA is relatively prime to nn, Ax mod nA^x \bmod n can never be 00. As there are only nn possible residues (11 to n−1n-1), the sequence must eventually repeat.

    • If Ai mod nextisthesameasAi+j mod nA^i \bmod n ext{ is the same as } A^{i+j} \bmod n, then due to GCD(A,n)=1GCD(A, n) = 1 (implying AA has a multiplicative inverse modulo nn), it must be that Aj mod n=1A^j \bmod n = 1. This signifies a periodic sequence.

  • Definition of Order (RR):

    • The order of AA modulo nn, denoted as RR, is the smallest positive integer (R>0R > 0) such that AR mod n=1A^R \bmod n = 1 .

  • Examples with n=15n=15:

    • Example 1: Let A=4A=4.

      • 41 mod 15=44^1 \bmod 15 = 4

      • 42 mod 15=16 mod 15=14^2 \bmod 15 = 16 \bmod 15 = 1

      • The order of 44 modulo 1515 is R=2R = 2.

    • Example 2: Let A=7A=7.

      • 71 mod 15=77^1 \bmod 15 = 7

      • 72 mod 15=49 mod 15=47^2 \bmod 15 = 49 \bmod 15 = 4

      • 73 mod 15=(4imes7) mod 15=28 mod 15=137^3 \bmod 15 = (4 imes 7) \bmod 15 = 28 \bmod 15 = 13

      • 74 mod 15=(13imes7) mod 15=91 mod 15=17^4 \bmod 15 = (13 imes 7) \bmod 15 = 91 \bmod 15 = 1

      • The order of 77 modulo 1515 is R=4R = 4.

    • Example 3: Let A=11A=11.

      • 111 mod 15=1111^1 \bmod 15 = 11

      • 112 mod 15=121 mod 15=111^2 \bmod 15 = 121 \bmod 15 = 1

      • The order of 1111 modulo 1515 is R=2R = 2.

Factoring nn Using the Order RR (Classical Success Conditions)

  • Premise: If we can find the order RR of AA modulo nn (where AR mod n=1A^R \bmod n = 1), we can potentially find a factor of nn.

  • Condition 1: RR must be an even number.

    • If RR is even, we can write R=2TR = 2T for some integer TT.

    • Then A2T mod n=1A^{2T} \bmod n = 1, which implies (AT)2 mod n=1(A^T)^2 \bmod n = 1.

    • Rewriting, we get (AT)2−1 mod n=0(A^T)^2 - 1 \bmod n = 0, or (AT−1)(AT+1) mod n=0(A^T - 1)(A^T + 1) \bmod n = 0.

  • Condition 2: AT−1ot mod n=0A^T - 1 ot\bmod n = 0.

    • This condition is crucial. It is guaranteed by the definition of RR as the smallest positive integer such that AR mod n=1A^R \bmod n = 1. If AT−1 mod n=0A^T - 1 \bmod n = 0, then AT mod n=1A^T \bmod n = 1. Since T=R/2T = R/2 and T<RT < R, this would contradict RR being the smallest order.

  • Factoring Step: If both conditions are met (i.e., RR is even AND AR/2+1ot mod n=0A^{R/2} + 1 ot\bmod n = 0), then GCD(AR/2+1,n)GCD(A^{R/2} + 1, n) will yield a non-trivial factor of nn (either pp or qq).

    • This works because (AR/2−1)(AR/2+1)(A^{R/2} - 1)(A^{R/2} + 1) is a multiple of n=pqn=pq, and neither AR/2−1A^{R/2}-1 nor AR/2+1A^{R/2}+1 is a multiple of nn. Thus, pp (or qq) must divide one term, and qq (or pp) must divide the other.

  • Probability of Success: For a randomly chosen coprime AA, the probability that RR is even AND AR/2+1<br>ot mod n=0A^{R/2} + 1 <br>ot\bmod n = 0 is typically greater than 0.50.5. Repeated trials with different AA values significantly increase the chances of success.

  • Example with n=15,A=7n=15, A=7:

    • Order R=4R=4, which is even. T=R/2=2T = R/2 = 2.

    • AT−1=72−1=49−1=48A^T - 1 = 7^2 - 1 = 49 - 1 = 48. 48<br>ot mod 15=048 <br>ot\bmod 15 = 0. So Condition 2 holds.

    • AT+1=72+1=49+1=50A^T + 1 = 7^2 + 1 = 49 + 1 = 50. 50 mod 15=550 \bmod 15 = 5. This is not 00. So AR/2+1<br>ot mod n=0A^{R/2} + 1 <br>ot\bmod n = 0 holds.

    • GCD(50,15)=GCD(5,15)=5GCD(50, 15) = GCD(5, 15) = 5. A factor (5) successfully pops out.

  • Example with n=15,A=11n=15, A=11:

    • Order R=2R=2, which is even. T=R/2=1T = R/2 = 1.

    • AT−1=111−1=10A^T - 1 = 11^1 - 1 = 10. 10<br>ot mod 15=010 <br>ot\bmod 15 = 0.

    • AT+1=111+1=12A^T + 1 = 11^1 + 1 = 12. 12<br>ot mod 15=012 <br>ot\bmod 15 = 0.

    • GCD(12,15)=3GCD(12, 15) = 3. A factor (3) successfully pops out.

The Quantum Advantage: Finding the Order RR

  • Classical Difficulty: Classically, finding the order RR of AA modulo nn is computationally hard. The best classical approach is to compute powers A1,A2,ext…A^1, A^2, ext{…} until 11 is found, which can take up to RR steps. Since RR can be comparable in size to nn, this problem is as hard as factoring itself and is related to the discrete logarithm problem.

  • Quantum Solution: Shor's algorithm provides a quantum component specifically for order finding. Given AA and nn, the quantum algorithm can find RR with very high probability in polynomial time (in the number of bits of nn).

  • Overall Efficiency: This efficient quantum order-finding step, combined with the successful classical steps, allows Shor's algorithm to factor nn in polynomial time on a quantum computer, making it exponentially faster than any known classical factoring algorithm.