Shor’s algorithm is one of the most famous quantum algorithms, created by mathematician Peter Shor in 1994. It showed, for the first time, that a quantum computer could solve a problem much faster than any known classical method.
The problem it solves is called integer factorization, breaking a large number \( N \) into the prime numbers that multiply to make it:
\[ N = p \times q \]
This is important because the security of many encryption systems, such as RSA, is based on the fact that factoring large numbers is slow on classical computers.
Finding the period r is where quantum computing shines. A classical computer would need to test many values of \( x \), but a quantum computer can find \( r \) quickly using a process called the Quantum Fourier Transform (QFT).
Once the period is known, the remaining steps are simple math done on a normal computer to find the factors.
Let’s understand how Shor’s Algorithm works using a simple example: finding the prime factors of N = 15.
Pick an integer such that \( 1 < a < N \). Let’s pick \( a = 2 \).
\( \text{gcd}(2, 15) = 1 \) → no factor found, continue.
\( f(x) = a^x \bmod N = 2^x \bmod 15 \)
| x | 2x | 2x mod 15 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 2 | 2 |
| 2 | 4 | 4 |
| 3 | 8 | 8 |
| 4 | 16 | 1 |
The pattern repeats every 4 steps.
The period \( r \) is the smallest number such that \( a^r \equiv 1 \ (\text{mod } N) \). Here, \( 2^4 \equiv 1 \ (\text{mod } 15) \). So, \( r = 4 \).
On a real quantum computer, the Quantum Fourier Transform (QFT) is used to find \( r \) efficiently. This is where the quantum speed-up happens — QFT finds the period exponentially faster than classical methods.
Once \( r = 4 \) is known:
\( a^{r/2} = 2^2 = 4 \)
Compute the gcd values:
✅ The factors of 15 are 3 and 5.
In simple terms: Shor’s algorithm turns a hard factorization problem into an easy period-finding problem, and uses quantum waves to find that period almost instantly.