We're here! We've made it. Finally after all the build-up, we're finally ready to see how quantum computers can factor large numbers into prime factors!
And quite surprisingly, this may be one of the shortest articles. We won't even use any quantum computing here!
Being able to factor large numbers is hugely important since it forms the backbone of all modern encryption. Specifically, RSA encryption uses a system where we define some number such that where and are large prime numbers. forms the "public" key that is exposed to everyone and and form the "private" that should be kept secret.
So we can see that having some machine that could factor composite numbers quickly would allow us to easily obtain the private key from the public key.
We won't go into the specifics of RSA encryption here, but just know that factoring would give an attacker the ability to read any encrypted message sent to the owner of the private keys.
Shor's algorithm was first proposed by Peter Shor in 1994. In fact, we've already seen half of it. In his original paper: "Algorithms for Quantum Computation: Discrete Logarithms and Factoring" he first presented the fast quantum algorithm for solving the order-finding problem and then showed that that algorithm gives us a way to do factorisation.
Let's see how we can use order-finding to factor !
We start by choosing some random value such that . We then calculate the greatest common divisor of and . If the greatest common divisor is not 1, then we have found a factor of (either or ) already, so we can stop here. If the greatest common divisor is 1, then we move on to the next step.
Since and are co-prime we know that there must exist some such that:
This is our order-finding problem. We simply use our fast quantum algorithm from the previous article to find .
If turns out to be odd, we're out of luck and we must try another value of . Once we've got an even value of we know that for some so we have:
This looks really promising as we have two integers on the left hand side which multiply to a value that is congruent to mod . This is another way of saying that divides . More specifically:
where is an integer.
This must mean that and appear somewhere in the prime factorisation of the numerator since .
We will use an already existing fast classical algorithm to compute the greatest common divisor (we will use the term from now on) of and . If (in other words, is a multiple of ) then it unfortunately means we have both and in the factorisation of so we can't extract any factors and we have to start our algorithm again from the begining.
Taking a look at the other term, it is actually always the case that . This is because if was a multiple of then we would have which would mean that, since and thus , we would have found a smaller order of and . Our order-finding algorthim is always guaranteed to give us the smallest possible order so this would be a contradiction.
Ok, so we're now at a point where neither or are a multiple of . But since their product is divisible by it must be the case that one of them is a multiple of and the other a multiple of .
This means calculating and will now give us our factors and .
Apply the above algorithm to factor the number .
This is amazing! Our fast order-finding quantum algorithm has given us a tool to factor large numbers into their prime factors without needing any extra quantum algorithm!
Now if had more than two prime factors we might require some more work to find the other factors, but the process remains more-or-less the same. The final two operations will always yield two non-trivial (not or ) factors.