The period of modular exponentiation is the smallest integer s.t. .
Shor's algorithm: finds the smallest positive integer s.t. for coprime and .
The difficulty of computing is the basis of the RSA Protocol.
RSA Protocol (Aside)
Let by the set of positive integers smaller than which are coprime to . Then suppose Alice wants to send a message to Bob securely.
Bob chooses two large primes and and a large .
Bob computes and communicates and to Alice over a public channel.
Eve also knows and , but not and , since factoring is hard (!).
Alice encodes her message as and sends to Bob.
Bob computes s.t. . This is easy only if you know and .
Bob computes .
Eve can break RSA if she can find the period of .
Pick coprime to .
Find the period of . This is hard classically, but easy quantumly. If is even (high probability), continue, else pick a new .
Find . We have .
Now since is the smallest positive integer s.t. . If , then restart with a new .
is a multiple of and is a multiple of . So, and . This breaks Shor's algorithm, since we can now compute and decrypt Alice's message!
Note that is even and with high probability, so this is a very effective attack.
2. Shor's Algorithm
Let be the number of bits of . Use output qubits and input qubits. We start as usual:
Then, we measure output . This collapses the input to a superposition of all s.t. . Let be the period of . Then, we have:
This is because:
Where is the smallest value such that , .
To get , we apply a Quantum Fourier Transform. This takes a value out of the Ket and puts it in the exponent:
So:
We can then perform a measurement on with probability:
This is because multiplying by a phase does not change the magnitude of a complex number.
3. Classical Postprocessing
To extract , we need to show that the numbers for which is large are for some and .
Using that .
Now that and , we have . Hence, is large, and with , and when is small, we have:
Now, we can use for , and since , we have:
Finally, the probability of any is:
Hence, there is a probability of at least that we will measure such that:
This can be shown to be enough to obtain as all other numbers with are at least apart. can then be obtained using the continued fractions algorithm.
One can show that and are coprime with probability , and then the denominator of is the period. In practice, run Shor's algorithm and check if . If not, run again.
Classical
Quantum
4. Implementing the Oracle
To implement , note that we can write it as the composition of functions:
Now introduce:
: modular multiplier.
.
Then, we can implement for as:
5. Quantum Fourier Transform
To implement , assume wlog , and . Then:
Now write , and use for to get:
Hence, we have:
Note that we can write , as for . So, .
We introduce a single cubit gate , which is a rotation by . Then, we can write to denote the controlled version of with the control on qubit and target on qubit . Then:
Now, using permutation, we can see that:
So, we need swaps, Hadamards, and controlled rotations, so gates. Classical fourier transform takes - but this is NOT an expontential speedup for the fourier transform problem, since LOADING the input takes time.