Shor's Algorithm Explained: How Quantum Computing Threatens RSA

 38 min video

 7 min read

YouTube video ID: k_kyepATqB8

Source: YouTube video by ComputerphileWatch original video

PDF

Shor's algorithm is a quantum computing algorithm famous for its theoretical ability to break certain cryptographic systems, particularly RSA. This article will delve into how Shor's algorithm works, its classical and quantum components, and the underlying physics that makes it possible.

The RSA Problem and Integer Factorization

RSA is a widely used public-key cryptography algorithm, essential for digital signatures and certificates on the internet. It relies on the difficulty of integer factorization. The public key in RSA contains a very large semi-prime number, N, which is the product of two secret prime numbers, P and Q. If P and Q can be found, the private key can be derived, allowing for the forgery of digital signatures and potentially enabling malicious activities like spoofing websites.

Classically, factoring large numbers (the integer factorization problem) is extremely difficult and time-consuming, taking hundreds of millions of years for realistic key sizes with current computing power. Shor's algorithm offers a much faster way to achieve this.

Shor's Algorithm: Reframing the Problem

Shor's algorithm reframes the integer factorization problem into a period-finding problem. Instead of directly factoring N, it constructs a function that loops periodically back to one. The goal is to find the period (R) of this function. If R is found, it's relatively straightforward to extract P and Q.

The function used is of the form A^R mod N, where A is a randomly chosen number between 2 and N-1. If the algorithm fails for a particular A, a new A is chosen, and the process is repeated.

Classical Period Finding Example

Let's illustrate the classical part of period finding with an example: Assume N = 15 and A = 2. We calculate increasing powers of 2 modulo 15:

  • 2^0 mod 15 = 1
  • 2^1 mod 15 = 2
  • 2^2 mod 15 = 4
  • 2^3 mod 15 = 8
  • 2^4 mod 15 = 16 mod 15 = 1

The sequence of results is 1, 2, 4, 8, 1, 2, 4, 8... The function repeats every 4 steps. Therefore, the period R = 4.

Extracting P and Q from the Period (R)

Once R is found, we use the following relationship: A^R ≡ 1 (mod N)

This means A^R - 1 is a multiple of N. We can factor A^R - 1 using the difference of squares: A^R - 1 = (A^(R/2) - 1) * (A^(R/2) + 1)

Since A^R - 1 is a multiple of N (which is P * Q), it's highly probable that (A^(R/2) - 1) or (A^(R/2) + 1) shares a factor with N (i.e., P or Q). We can then find P or Q by calculating the greatest common divisor (GCD) of (A^(R/2) - 1) and N, or (A^(R/2) + 1) and N.

Continuing our example with N=15, A=2, and R=4: A^(R/2) + 1 = 2^(4/2) + 1 = 2^2 + 1 = 4 + 1 = 5 The GCD of 5 and N (15) is 5. Since the factors of 15 are 3 and 5, we have successfully found one of the prime factors (5). The other factor (3) can be easily obtained.

This re-framing of integer factorization into a period-finding problem is crucial because quantum computers excel at finding the period of large functions.

The Quantum Component: Fourier Analysis and Wave Interference

The quantum part of Shor's algorithm leverages the principles of Fourier analysis and wave interference to efficiently find the period.

Periodicity and Fourier Transforms

Physicists are adept at dealing with periodicity and frequency. Fourier transforms break down complex patterns into a sum of simpler sine and cosine waves. Each wave has a specific frequency and phase.

Consider a simple pattern, like a zebra crossing. A Fourier transform can identify the key frequencies that make up this pattern. The "spatial frequency" indicates how many cycles repeat across the image. The average contrast of an image corresponds to a zero-frequency component (DC level). As more components (waves of different frequencies and phases) are added, the image becomes sharper and more detailed.

In Shor's algorithm, we perform Fourier decomposition. We have the function's output (e.g., 1, 2, 4, 8, 1, 2, 4, 8...) and want to find its period. A Fourier analysis of this sequence will reveal the dominant frequencies, and the first significant peak in the Fourier spectrum directly corresponds to the period (R) of the function.

Wave Interference and Quantum Mechanics

The core mechanism underpinning quantum computing is the interference of waves. This is not a bizarre or mystical phenomenon but a fundamental aspect of wave physics.

  • Constructive Interference: When waves align (are "in phase"), their amplitudes add up, resulting in a larger wave.
  • Destructive Interference: When waves are misaligned (are "out of phase"), their amplitudes cancel each other out, resulting in a smaller wave or no wave at all.

Quantum computers precisely control the phase of quantum waves to achieve constructive and destructive interference. This allows them to amplify the correct answer (the period) and cancel out incorrect ones.

Qubits and Superposition

A qubit, the basic unit of quantum information, can exist in a superposition of states (0 and 1 simultaneously), unlike a classical bit which is either 0 or 1. This is analogous to waves existing in multiple states at once.

In a trapped-ion quantum computer, for example, two energy states of an ion can represent 0 and 1. Microwave pulses are used to manipulate the probability of the ion being in either state, creating a superposition. The "brightness" of the ion when illuminated by a laser indicates its state, but making a measurement "collapses" the superposition, forcing the ion into a definite state (0 or 1). This means the system must be reset and measured repeatedly to gather statistical information.

Representing Quantum States with Phasors

Richard Feynman's approach uses "phasors" – arrows rotating on a vinyl record – to visualize quantum states.

  • Energy and Frequency: In quantum mechanics, energy is directly related to frequency (E = hf). A lower energy state corresponds to a slower rotation of the phasor, while a higher energy state corresponds to a faster rotation.
  • Probability and Arrow Length: The length of the phasor arrow represents the amplitude of the quantum state. The square of this length gives the probability of measuring the system in that state.
  • Phase Control: The position of the arrow on the circle represents the phase of the quantum wave. By precisely controlling the phase of these quantum waves, quantum computers can orchestrate constructive and destructive interference.

When a quantum Fourier transform is applied, the quantum computer effectively performs a massive parallel computation by allowing different possible solutions to interfere. The correct period will constructively interfere, leading to a higher probability of being measured, while incorrect periods will destructively interfere, making them less likely to be observed.

Practicality and Future Outlook

Currently, quantum computers are "noisy" and limited in size. Factoring a number like 15, which is trivial for a classical computer, is still a significant challenge for existing quantum machines. Therefore, breaking a 2000-bit RSA key is not yet feasible.

The timeline for when quantum computers will be powerful enough to break RSA is uncertain, ranging from 5 to 100 years. However, the potential impact on cryptography is so profound that it necessitates proactive research into post-quantum cryptography.

The engineering challenge lies in maintaining the "quantumness" of the system by isolating qubits from environmental noise, which can disrupt the delicate phase relationships crucial for interference. Despite these challenges, the underlying principles of Shor's algorithm and quantum mechanics demonstrate that the calculations happen within this universe, without needing recourse to parallel realities or infinite pixies. The speedup comes from the elegant use of wave interference to efficiently find the period of a function, rather than brute-forcing every possible factor.

  Takeaways

  • Shor's algorithm transforms integer factorization into a period-finding problem, allowing a quantum computer to extract RSA prime factors efficiently.
  • The classical part selects a random base A and uses the relationship A^R ≡ 1 (mod N) to derive the period R, which leads to the factors via GCD calculations.
  • Quantum Fourier transform and wave interference amplify the correct period while canceling incorrect ones, leveraging constructive and destructive interference of qubit phases.
  • Qubits in superposition and precise phase control enable massive parallelism, but current noisy quantum hardware can only factor tiny numbers like 15.
  • Although breaking a 2000‑bit RSA key may be decades away, the threat drives urgent development of post‑quantum cryptographic schemes.

Frequently Asked Questions

Why does Shor's algorithm reframe integer factorization into a period-finding problem?

Shor's algorithm reframes integer factorization as a period‑finding problem because the period R of the function f(x)=A^x mod N reveals a congruence A^R ≡ 1 (mod N) that can be exploited to compute the greatest common divisor with N and recover the prime factors. Quantum computers can determine R efficiently using the quantum Fourier transform, something classical algorithms cannot do quickly.

How does the quantum Fourier transform enable constructive interference of the correct period in Shor's algorithm?

The quantum Fourier transform maps the superposition of all possible function evaluations into the frequency domain, where amplitudes associated with the true period add constructively while those linked to incorrect periods interfere destructively. This amplification makes measuring the correct period far more likely, enabling the algorithm to extract the factor‑relevant information efficiently.

Who is Computerphile on YouTube?

Computerphile is a YouTube channel that publishes videos on a range of topics. Browse more summaries from this channel below.

Does this page include the full transcript of the video?

Yes, the full transcript for this video is available on this page. Click 'Show transcript' in the sidebar to read it.

can be found, the private key can be derived, allowing for the forgery of digital signatures and potentially enabling malicious activities like spoofing websites. Classically, factoring large numbers (the integer factorization problem) is extremely difficult and time-consuming, taking hundreds of millions of years for realistic key sizes with current computing power. Shor's algorithm offers

much faster way to achieve this.

Helpful resources related to this video

If you want to practice or explore the concepts discussed in the video, these commonly used tools may help.

Links may be affiliate links. We only include resources that are genuinely relevant to the topic.

Full transcript is not shown on this page

This page focuses on the summary and original notes. For full verification, refer to the original YouTube video.

PDF