Breaking RSA Using Shor's Algorithm
Our construction
Reference implementation
To avoid overloading the reader, we will describe our factoring construction by starting from a simple reference implementation of the quantum part of Shor's original algorithm and then apply optimizations one by one.
The reference implementation works the way most implementations of
Shor's algorithm do, by
decomposing exponentiation into iterative controlled modular
multiplication.
A register is initialized to the
state, then a controlled modular
multiplication of the classical
constant
into
is performed, controlled by the qubit
from the
exponent
, for
each integer
from
down to 0. After the multiplications are
done,
is storing
and measuring
completes the hard part of Shor's algorithm.
Controlled modular multiplication is still not a primitive operation, so
it must also be decomposed. It can be performed by introducing a work register y initialized
to and then performing
the following two controlled scaled additions:
then
.
After these two operations,
is storing the result and
has been
cleared to the
state. Swapping
the two registers, so that the result is in
, completes the
multiplication.
Performing a controlled scaled addition with classical scale factor
can be done with a series of
controlled modular additions. For each qubit
in the input register,
you add
into
the target, controlled by
. Controlled modular addition in turn is
performed via a series of non-
modular additions and comparisons. Finally,
using the Cuccaro adder, uncontrolled non-modular additions can be
performed with
additional workspace using
Toffolis.
Combining the numbers in the preceding two paragraphs implies a Toffoli
count of for the reference implementation. It constitutes the baseline for
the optimizations that we apply in the following sections.