We are going to crack the RSA by finding the period of the ciphertext. Let m be the message, c the ciphertext, e the encoding number and N=pq such that
c=memodN
From Period Finding and the RSA post, the period of a ciphertext is defined as the smallest number r such that
cr≡1modN
First we prepare n=2n0 QBits at the state ∣0⟩ where n0 is the number of bits of N=pq. The number of bits can be computed using the formula:
⌈log2(N)⌉
We also prepare n0 QBits for the output register.
So initially we have the following setup:
n times∣00…0⟩⊗n0 times∣00…0⟩
The output register will contain the output of the operator:
Uf∣x⟩∣0⟩=∣x⟩∣f(x)⟩
where
f(x)=cxmodN
We now apply the Hadarmard gate to the input register and apply the operator Uf:
2n/21x=0∑2n−1∣x⟩∣f(x)⟩
The Hadamard gates transform the state into a superposition of all possible values of the period while the operator Uf transforms the output QBits as superposition of all possible values of cxmodN.
Next we make a measurement of the output QBits. This will give us a number f0 which corresponds to all states whose value of ∣x⟩ is of the form x0+kr since
cx0+kr≡cx0ckrmodN≡cx0(cr)kmodN≡cx0modN
since (cr)k≡1modN by definition of a period.
Therefore, after the measurement, the input state is now
∣Ψ⟩=m1k=0∑m−1∣x0+kr⟩
where m is the smallest integer such that x0+mr≥2n.
We will then apply the quantum Fourier transform to state ∣Ψ⟩. The Quantum Fourier Transform is defined by its action on an arbitrary ∣x⟩
Now if we make a measurement of this new state, the probability of getting a value of y is the probability amplitude multiplied by it's complex conjugate:
Therefore, the probability of getting a specific y is
p(y)=2nm1sin2(πf)sin2(πfm)
Here is a plot of the function sin2(πfm)/sin2(πf) for m=4:
Notice that the graph attains its maximums when the values of f are integer values, that is when
f=j=2nry where j=1,2,3,4,…,r
Since y is an integer value, this means that the value of y must be close to j2n/r. We can use a theorem in Number theory which states that if p/q is a rational number that approximates a real number x and
qp−x≤2q1
we can approximate x using continued fraction expansion of p/q. In fact, if we find a y that is within 1/2 of one of the j2n/r values, we have
y−jr2n≤21
and dividing both sides by 2n, we get
2ny−rj≤2n+11
which satisfies the theorem. We can therefore expand y/2n via continued fraction expansion and continue until we find a denominator r that is less that 2n0. We then test whether r could be our period if it satisfies
cr≡1
If it satisfies the above, then r is the period. It's just a matter of computing d′, the inverse of e modulo r satisfying
ed′≡1modr
Having computed d′, we can then decrypt the ciphertext using
m=cd′modN
In our example in period finding, let's suppose that the quantum computer gave us the following number
y=1446311
We can expand the fraction y/2n=1446311/16777216 as a continued fractions as follows:
We can approximate the denominator using the small angle approximation of sine:
sin(x)≈x
to get
p(yj)=2nm1[2nπrδj]2sin2[2nπmrδj)]
Since m is the smallest integer such that x0+mr≥2n, then
m=⌈r2n⌉
We can use this to approximate
m2nr≈1
to get
p(yj)=2nm1(mπδj)2sin2(πδj)
Since 0≤δj≤1/2, we can see from the graph below that the line joining (0,0) and (π/2,1), whose equation is 2x/π is less that the value of the sine function at that interval, that is,
π2x≤sin(x)
Using this inequality, we can get a lower bound of the probability of getting a specific y value to be
Since there are r of these yj's, the probability of getting any one of these yj's is therefore:
p(y)=π24≈0.405
which means that there is 40% probability of the state to collapse to a value of y that will give us the correct period.
We have just seen how a quantum computer can be used to crack the RSA. We have exploited the fact that the measurement will give us a value of y that is near j2n/r with high probability. We then computed for the period using the continued fraction expansion of y/2n. With the period computed, it's becomes straightforward to decrypt the ciphertext.