414 Shor’s factorization algorithm
It is readily checked that 561 = 33 ×17 = 3 ×187 = 11 ×51 ≡ 3 ×11 ×17, which
shows that GCD(x
i
± 1, N ) is always a factor of N . We also observe that given a single
solution x
i
, one of the two corresponding GCD, i.e., GCD(x
i
± 1, N ), is a prime factor
of N (namely, 3, 11, or 17). The calculation of the six GCDs corresponding to the three
solutions x
1
, x
2
, x
3
, namely, GCD(x
1
± 1, N ), GCD(x
2
± 1, N ), and GCD(x
3
± 1, N ),
thus, makes it possible to factorize N completely.
The lesson learnt from Theorem 1 and these two illustrative examples is that the
knowledge of any single (nontrivial) solution of x
2
= 1modN yields two factors of N .
The complete factorization of N can, thus, be achieved by repeating the process with the
remaining factors (call any of these N
), provided that for each we can find a solution
of x
2
= 1modN
. What is the computation cost of the algorithm used to determine the
GCDs? There exist several possible answers to this question, depending on the algorithm
choice and its implementation. It can be shown that for L digit numbers, the extended
Euclidian algorithm complexity is of the order of O(L
2
) or better and, furthermore, that
there exist other algorithms for which finding the GCD is reduced to O[L(ln L)
2
ln ln L].
The continued fraction expansion algorithm, which was described in Section 20.3, can
be also implemented for this purpose but, as we have seen, its complexity is O(L
3
). Here,
we may only retain that finding the GCD through the extended Euclidian algorithm is,
at most, of the order of O(L
2
).
While Theorem 1 enables one to factorize a given composite number N rapidly, it
exclusively relies on prior knowledge of at least one nontrivial solution of x
2
= 1modN.
But how can we get this knowledge? This is where the order-finding algorithm, which
was described in Section 20.2, nicely comes to the rescue. As we have seen, given
any integer x, such that 1 ≤ x ≤ N − 1, the order of x modulo N is the smallest
number r for which x
r
= 1modN. In the case where r is even,lety = x
r/2
. We, thus,
have y
2
= 1modN, which shows that y is a solution of the Theorem 1 equation. If
y =±1modN , then y is a nontrivial solution of the equation and, according to the
theorem, GCD(y ± 1, N ) = GCD(x
r/2
± 1, N ) is a factor of N . In this case, the order-
finding algorithm successfully yields a determination of a factor of N.Ify is a trivial
solution, the algorithm fails, and the order-finding algorithm must be implemented again,
using a different trial value for x. The same conclusion applies when r turns out to be
odd. The fact that the algorithm may fail should not be perceived as an embarrassing
weakness of the factoring endeavor. It just takes a finite number of order-finding trials
(each of O(L
3
)) to lead to a successful and conclusive step, and as many such trials
to eventually achieve the full factorization. Actually, a second theorem shows that the
convergence of the algorithm is strong. This theorem states:
T 20.2 Given N, an odd composite integer with the factorization N =
p
α
1
1
p
α
2
2
... p
α
k
m
, where p
i
are prime numbers (α
i
integers), and given an integer x chosen
at random in the interval
[
1, N − 1
]
and co-prime to N, the probability that r is even
and y = x
r/2
is a nontrivial solution of y
2
= 1modN satisfies
p ≥ 1 −
1
2
m
. (20.29)