RSA Manuscript
RSA Manuscript
1. Introduction
In this paper we give a polynomial time algorithm to compute φ(N )
for an RSA module N using as input the order modulo N of a ran-
domly chosen integer. The algorithm consists only on a computation
of a greatest common divisor, two multiplications and a division (see
Theorems 3.9 and 2.1). As it is well-known, from this value it is easy
to factor N by just solving a quadratic equation. The algorithm works
with a probability greater than 1− NC1/2 , where C is a constant (in prac-
tice it could be C = 16 for example), and the input can be obtained
from a quantum computer by a single application of Shor’s algorithm
(cf. [7] and [8]), assuming that the output of that algorithm is exactly
the order module N of a randomly chosen integer. This assumption is
reasonable since, as explained in [3], the probability that Shor’s algo-
rithm fails to give the right order is negligible, under suitable conditions
on the parametrization and post-processing of the quantum algorithm
(cf. [3], section 2.1).
1we omit here the term −1/2k , where k denotes the number of iterations, since
this term is dominated by the other, for k sufficiently large
COMPUTING φ(N ) FOR AN RSA MODULE WITH A SINGLE QUANTUM QUERY
3
We remark that our results can be easily adapted to cover also the
case of arbitrary RSA modules. In fact, if we assume that both prime
factors of N are larger than N 1/4 then a result similar to Theorem 3.9
can be proved, just changing 1 − NC1/2 by 1 − NC1/4 in the probability
of success. On the other hand, there is no need to consider the case
where one of the prime factors of N is smaller than N 1/4 , since as it
is well-known in that case the method of Coppersmith (see [1]) gives a
polynomial time deterministic algorithm to factor N (with a classical
computer).
The following notation will be used through the whole paper. Given
two integers a, b, (a, b) will be their greatest common divisor, while
[a, b] will be their least common multiple. It will be useful to recall
that
(1.1) ab = [a, b](a, b)
Also, N = pq will be the product of the two prime numbers p and q
such that
Y r
p−1 = pai i P
i=1
r
Y
(1.2) q−1 = pbi i Q
i=1
where
p+q
0< < 1,
D
so
N +1
= X,
D
and once we know X, then we know (p − 1)(q − 1) and we solve the
system
N = pq
N + 1 − DX = p + q.
Corollary 2.2. Let N = pq be the product of two unknown prime
numbers p, q of at most L bits, say p < q ≤ 2L . Suppose we know D
such that DX = (p − 1)(q − 1) and D ≥ 2L+1 . Then,
N +1
φ(N ) = D.
D
Theorem 2.3. Let N = pq be the product of two unknown prime
numbers p, q of at most L bits, and suppose (p − 1, q − 1) = D > 2L/2+1
is known. Then we can factor N in polynomial time.
Proof. We know that
p = 1 + Rp D
q = 1 + Rq D,
where Rq + Rp < D by our conditions. Then since
N = 1 + (Rq + Rp )D + Rq Rp D2
we get
N −1
Rp + Rq = (mod D),
D
in particular reducing N − 1/D modulo D we get Rp + Rq and, from
there p + q = 2 + Rp D + Rq D and we factor N by solving the system
in p + q and pq as before.
Suppose ordN (a) = x and let (x, y) = 1. Then ordN (ay ) = x. In-
deed suppose ordN (ay ) = z. Since (ay )x = (ax )y = 1 (mod N ), z|x.
But we know that for some integers u, v we have az = (az )uy+vx =
(ay )zu (ax )zv = 1, so x|z and they are the same.
Now, we see that every element in Cx1 ,x2 has order x1 x2 . First note
that (ai bj )x1 x2 = 1 (mod N ), so ordN (ai bj )|x1 x2 Suppose ordN (ai bj ) =
z then z = z1 z2 where z1 = (z, x1 ), and z2 = (z, x2 ), but then
(ai bj )z1 z2 = 1 (mod N ) so (azi 2 )z1 = ((bj )−1 )z1 )z2 , but ordN (azi 2 ) = x1
and ordN (bj )−1 )z1 = x2 , so they can not be equal unless z1 = x1 and
z2 = x2 . On the other hand ai bj ̸= aI bJ for any (i, j) ̸= (I, J), again
for the same reason since otherwise aaIi = bbJj which is impossible since
ordN ( aaIi )|x1 and ordN ( bbJj )|x2 .
So we have proved that the n1 n2 elements in Cx1 ,x2 are indeed dis-
tincts and have order x1 x2 . Now we need to prove that there are no
more. Suppose w ∈ (Z/N Z)∗ has ordN (w) = x1 x2 . We will prove that
w is the product of two elements w = ai bj for ai ∈ Cx1 and bj ∈ Cx2 .
But for some integers u, v such that (ux1 , vx2 ) = 1 we have
w = wux1 +vx2 = wux1 wvx2
But if ordN (wux1 ) = z then z|x2 and (u, z) = 1 so ordN (wx1 ) = z and
hence z = x2 in the same way we prove that ordN (wvx1 ) = x1 finishing
the proof of the lemma.
COMPUTING φ(N ) FOR AN RSA MODULE WITH A SINGLE QUANTUM QUERY
7
0≤ci ≤mi
αi ≤mi
p i αi >mi
x Y 1
= φ(Px Qx )(x, N − 1)φ( ) 1+
Px Qx α ≤m pi
i i
X µ2 (d)
= φ(x)(x, N − 1) .
d
d|(x,N −1)
(d, (x,Nx−1) )=1
Lemma 3.3. Let N = pq be the product of two prime numbers p and
q and let D|[p − 1, q − 1]. Then, (D, p − 1, q − 1) = (D, N − 1).
8 LUIS VÍCTOR DIEULEFAIT AND JORGE URRÓZ
Proof. First we note that for any prime l so that la |[p−1, q −1] then
either la |p−1 or la |q−1 and hence, noting that N −1 = (p−1)q+(q−1),
if la |([p − 1, q − 1], N − 1), then la |(p − 1, q − 1) and hence we deduce
(D, N −1)|(D, p−1, q−1). On the other hand (D, p−1, q−1)|(D, N −1),
so they must be equal.
Corollary 3.4. If D|[p − 1, q − 1] then D(D, N − 1)|φ(N ).
Proof. Using the previous Lemma we see that
D(D, N − 1) = D(D, (p − 1, q − 1))
= [D, (D, (p − 1, q − 1))](D, (D, (p − 1, q − 1))
= D(D, (p − 1, q − 1))
and since D|[p − 1, q − 1] and (D, (p − 1, q − 1))|(p − 1, q − 1) we get
D(D, N − 1)|[p − 1, q − 1](p − 1, q − 1) = (p − 1)(q − 1) = φ(N ).
Corollary 3.5. Let p − 1 = ri=1 pai i P , q − 1 = ri=1 pbi i Q where a
Q Q
prime l|(p − 1, q − 1) if and only if l = pi for some 1 ≤ i ≤ r. Suppose
D
D|[p − 1, q − 1] and consider the sequence D1 = D, Dj+1 = (Dj ,Nj −1) .
Then for some j0 we have Dj = Dj0 for all j ≥ j0 and Dj0 |P Q.
Proof. Let mi = min{ai , bi } and suppose pαi i ||Dj for 1 ≤ i ≤ r.
Then if αi ≤ mi then pαi i ||(Dj , N − 1) and pi ∤ Dj+1 . If αi > mi then
αi −mi
pm
i ||(Dj , N − 1) and pi
i
||Dj+1 and iterating we get the result.
Remark 3.6. Observe that if D = ri=1 pαi i PD Q
Q
D
QDr = CαD PD QD , where
PD |P and QD |Q, then Dj0 = PD QD and Dj = i=1 pi . i
0
One can use the previous remark to give a result that allows factor-
ization directly in terms of (p − 1, q − 1), improving Theorem 2.3 in
some cases.
Theorem 3.7. Let N = pq where p and q and D = CD PD QD = CD Dj0
are as in Corollary 3.5 and denote F = (CD , N − 1). Then, if
(p − 1 + q − 1)
Dj0 > ,
F2
we can factor N in polynomial time.
Proof. The proof is the same as in Theorem 2.1. Note that
N − 1 − (p − 1 + q − 1) = φ(N ) = [p − 1, q − 1](p − 1, q − 1)
and since D|[p − 1, q − 1], and F |(p − 1, q − 1), we have
N − 1 − (p − 1 + q − 1) = DF X,
COMPUTING φ(N ) FOR AN RSA MODULE WITH A SINGLE QUANTUM QUERY
9
and
µ2 (d) µ2 (d)
X X Y 1
≤ = 1+ .
d d p
d|(x,N −1) d|(x,N −1) p|(x,N −1)
(d, (x,Nx−1) )=1
So, we can apply Theorem 2.1 with D = x(x, N − 1) to get the factor-
ization.
References
[1] D. Coppersmith. Small solutions to polynomial equations, and low exponent rsa
vulnerabilities. J. Cryptology, 10(233-266), 1997.
[2] J.-S. Coron and A. May. Deterministic polynomial time equivalence of comput-
ing the rsa secret key and factoring. Journal of Cryptology, (2004/208), 2004.
[3] M Ekera. On completely factoring any integer efficiently in a single run of an
order finding algorithm. Quantum Inf. Process, 20(205), 2021.
[4] F. Grosshans, T. Lawson, Morain F., and B Smith. Factoring safe semiprimes
with a single quantum query,. preprint at https://arxiv.org/pdf/1511.04385.
[5] National Institute of Standards and Technology. Digital signature standards.
FIPS, 186-5, 2023.
[6] R. Rivest, A. Shamir, and L. Adleman. A method for obtaining digital signatures
and public-key cryptosystems. Communications of the ACM, 21(2):120–126,
1978.
[7] P. W. Shor. Algorithms for quantum computation: Discrete logarithms and
factoring. SFCS, Proceedings of the 35th Annual Symposium on Foundations of
Computer Science, pages 124–134, 1994.
[8] P. W Shor. Polynomial-time algorithms for prime factorization and discrete
logarithms on a quantum computer. SIAM Journal on Computing, 26(5):1484–
1509, 1997.