-
Opinions expressed on these pages were the views of the writers and did not necessarily reflect the views and opinions of the American Mathematical Society.
Categories
- Academic Skills
- Advice
- Algebra
- Algebraic Geometry
- AMS
- Analysis
- Announcement
- Arts & Math
- Biology
- Book Reviews
- Conferences
- Crossword Puzzles
- Diversity
- Ecology
- Editorial Statement
- First-generation
- General
- Grad School
- Grad student advice
- Grad student life
- Interview
- Interviews
- JMM
- Jobs
- Linear Algebra
- MAM
- Math
- Math Education
- Math Games
- Math History
- Math in Pop Culture
- Math Teaching
- Mathematicians
- Mathematics in Society
- Mathematics Online
- News
- Number Theory
- Publishing
- puzzles
- Social Justice
- Starting Grad Schol
- Statistics
- staying organized
- Teaching
- Technology & Math
- Topology
- Uncategorized
- Voting Theory
Archives
- December 2021
- November 2021
- October 2021
- September 2021
- April 2021
- January 2021
- November 2020
- July 2020
- June 2020
- May 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- November 2018
- September 2018
- June 2018
- May 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
Meta
Shor’s Algorithm – Breaking RSA Encryption
In my previous article, I talked about the RSA cryptosystem which is widely used on the Internet for secure data transmission. The power and security of the RSA cryptosystem derives from the fact that the factoring problem is "hard." That is, it is believed that the full decryption of an RSA ciphertext is infeasible because no efficient classical algorithm currently exists for factoring large numbers. However, in 1994 Peter Shor showed that a quantum computer could be used to factor a number n in polynomial time, thus effectively breaking RSA.
It may be tempting to use the speed of a quantum computer to simply check all possible divisors in parallel. In this case, we would be performing a classical algorithm on a quantum computer, making use only of the increased speed of the quantum machine. Unfortunately, this is not going to work. In a way, it is possible for a quantum computer to try all possible divisors. However, due to the nature of quantum computing, when measuring the outcome of the computations, you will get a random possible divisor, which is almost certainly not the one you want.
How, then, can we use a quantum computer to solve the factoring problem? The key to a fast and accurate quantum factoring algorithm is to make use of the structure of the factoring problem itself. Instead of looking for factors directly, we must use some mathematical property of factoring. Fortunately, the factoring problem has plenty of special properties from which to choose. For example, given a positive integer, even if we do not know its prime factorization we do know that it has exactly one factorization. This fact does not help us solve the factorization problem, but it does give us hope that the problem has other nice mathematical properties that will.
The property we will use is the ability to reduce the prime factorization problem into a problem of order (or period) finding. Let’s start by looking at an example. Consider the sequence of numbers
2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, ...
Now, let’s look at this same sequence of powers of two, but taken "mod 15." In other words, we will create a new sequence of numbers consisting of the remainders when each power of two is divided by 15. This gives us the new sequence
2, 4, 8, 1, 2, 4, 8, 1, 2, 4, ...
We see that taking the powers of two mod 15 gives us a periodic sequence whose period (or order) is four. For another example, consider the same powers of two, but taken mod 21. In this case, we have the new sequence
2, 4, 8, 16, 11, 1, 2, 4, 8, 16, ...
Here, we get a periodic sequence whose period is six.
In the 1760s, Euler discovered a beautiful pattern to this period finding problem. Let n be the product of two prime numbers, p and q. Consider the sequence
x \text{ mod } n, x^2 \text{ mod } n, x^3 \text{ mod } n, x^4 \text{ mod } n,…
If x is not divisible by p or q, then the above sequence will repeat with some period that evenly divides (p-1)(q-1).
In our examples above, we have x = 2. In the first example, we have n = 15 which has the prime factors p = 3 and q = 5. Then, (p-1)(q-1) = 8, which is divisible by the period of 4. In the second example, we have n = 21 which has the prime factors p = 3 and q = 7. Then, (p-1)(q-1) = 12, which is divisible by the period of 6.
But how does this help us solve the factorization problem? If we can find the period of the sequence
x \text{ mod } n, x^2 \text{ mod } n, x^3 \text{ mod } n, x^4 \text{ mod } n,…
then we learn something about the prime factors of n. In particular, we learn a divisor of (p-1)(q-1). Of course, we’d rather learn the factors p and q themselves, but this, at least, represents progress. If we determine several random divisors of (p-1)(q-1) by trying different random values of x, then we can multiply those divisors together to obtain (p-1)(q-1) itself. Once we know (p-1)(q-1), we can then determine p and q.
However, there’s still a problem with applying our observations to the factorization problem. Even though the sequence
x \text{ mod } n, x^2 \text{ mod } n, x^3 \text{ mod } n, x^4 \text{ mod } n,…
will eventually start repeating itself, the number of steps before it repeats could be almost as large as n, which in the RSA cryptosystem is a very large number! This issue is why finding the period of the sequence does not appear to lead to a classical factoring algorithm. However, with the help of quantum mechanics, we can define a quantum algorithm that works in a reasonable amount of time.
Shor’s algorithm is composed of two parts. The first part turns the factoring problem into the period finding problem, and can be computed on a classical computer. The second part (step 2 below) finds the period using the quantum Fourier transform and is responsible for the quantum speedup of the algorithm. We begin by briefly describing all five steps. After that, we will focus on the quantum part of the algorithm (i.e. step 2). To factor a large integer n (which, without loss of generality, we may assume is odd), we use Shor’s algorithm:
1. Choose a random positive integer m < n. Compute gcd(m, n), which may be done in polynomial time using the Euclidean algorithm. If gcd(m, n)\neq 1, then we have found a non-trivial factor of n, and we are done. If, on the other hand, gcd(m, n) = 1, proceed to step 2.
2. Use a quantum computer to determine the unknown period P of the sequence
x \text{ mod } n, x^2 \text{ mod } n, x^3 \text{ mod } n, x^4 \text{ mod } n,…
3. If P is an odd integer, then return to step 1. The probability that P is odd is (\frac{1}{2})^k, where k is the number of distinct prime factors of n. If P is even, then proceed to step 4.
4. Since P is even,
(m^{P/2} - 1)(m^{P/2} - 1) = m^{P} - 1 = 0 \text{ mod } n.
If m^{P/2} +1 = 0 \text{ mod } n, then go to step 1. If m^{P/2} +1 \neq 0 \text{ mod } n, then proceed to step 5. It can be shown that the probability that m^{P/2} +1 = 0 \text{ mod } n is less than (\frac{1}{2})^{k-1}, where k denotes the number of distinct prime factors of n.
5. Compute d = gcd(m^{P/2}-1, n) using the Euclidean algorithm. Since m^{P/2} +1 \neq 0 \text{ mod } n, it can be shown that d is a non-trivial factor of n. Exit with the answer d.
Thus, the task of factoring an odd positive integer n reduces to the problem of finding the period of a function/sequence. Shor’s period-finding algorithm (step 2 above) relies heavily on the ability of a quantum computer to be in many states simultaneously (a superposition of states). To compute the period of a function f, we evaluate the function at all points simultaneously.
Unfortunately, quantum mechanics does not allow us to access all of this information directly. Instead, a measurement must be taken which will yield only one of the possible values (destroying all others). Because of this issue, we must transform the superposition to another state that will return the correct period with high probability. This is achieved by using the quantum Fourier transform. The main components of Shor’s period-finding algorithm are as follows:
1. Create a superposition of states. This can be done by applying Hadamard gates to all qubits in the input register.
2. Implement the function f as a quantum transform. To achieve this, Shor used repeated squaring for his modular exponentiation transform.
3. Perform a quantum Fourier transform.
After these transformations, a measurement will yield an approximation to the period P.
Now let’s look at an example of how n = 91 (= 7\cdot 13) can be factored using Shor’s algorithm.
Step 1. Choose a random positive integer m, say m = 3. Since gcd(91,3) = 1, proceed to step 2 to find the period of the function f given by
f(a) = 3^a \text{ mod } 91.
Step 2. Run Shor’s period-finding algorithm on a quantum computer to find (with high probability) that the period P = 6.
Step 3. Since P = 6 is even, we proceed to step 4.
Step 4. Since
3^{P/2} +1 =3^3 + 1 = 28 \neq 0 \text { mod } 91
proceed to step 5.
Step 5. With the Euclidean algorithm, compute
d = gcd(3^{P/2}-1, 91)= gcd(3^{3}-1, 91)= gcd(26, 91) = 13.
We have succeeded in using Shor’s algorithm to find a non-trivial factor of n = 91, namely d = 13.
Sources:
Shor, P. W. (1997). Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Journal on Computing, 26(5), 1484-26. doi:http://dx.doi.org/10.1137/S0097539795293172
Lomonaco, Jr, S. J. (2000) Shor’s Quantum Factoring Algorithm. arXiv:quant-ph/0010034
3 Responses to Shor’s Algorithm – Breaking RSA Encryption
Thanks very much for this. I found it very helpful for getting started on thinking about what one might actually do with a quantum computer.
I think there is an error, just a typo, in one of your equations. Where it says:
(m^(P/2)-1)(m^(P/2)-1) = m^P – 1
I think it should say:
(m^(P/2)-1)(m^(P/2)+1) = m^P – 1
I would be 100% sure about this, except that the topic is number theory, which often pulls the rug out from under my physicist brain. For example, the number 1 has entirely too many square roots in number theory, where the modulo n part is sometimes sort of an afterthought.
I think most people will just read around that error and either not notice, or else just know what you meant, although like I said, I am still not 100% sure. If it’s actually correct as is, you would help people like me by explaining how.
Again, thanks much,
Bill Peria
Hello, Bill.
I see the same typo in the equation.
I think you got this a little wrong. To begin with, Bill Peria is correct. You factored m^p – 1 incorrectly.
The next error is in step 4. You don’t want the = sign there, you want the ≡ congruence symbol.
m^P – 1 ≡ 0 Mod N
But if the next relation
m^(P/2) + 1 ≡ 0 Mod N
is true, stop. You found a factor of N. Why would you go back to step 1 at this point?
Comments are closed.