An implementation of EuclidAttack. Which is An application of Euclidean algorithm in cryptanalysis of RSA.
It computes the factorization of n in deterministic time O((log n)2) bit operations. In the case where the public exponent (e) has the same order of magnitude as (n) and one of the integers k = (ed − 1)/ϕ(n) and (e − k) is < n0.25.
-
Let p and q be two odd primes of the same bit-size L and n = pq.
-
Consider positive integers e, d with 1 < e, d < ϕ(n) such that ed ≡ 1 (mod ϕ(n)). Then (n, e) is the public key and d the private key for an RSA cryptosystem.
-
Set a = (n + 1) mod e and Δ = gcd(e, a).
-
The extended Euclidean algorithm for e and a gives integers qi > 0 (i = 1, . . . , m) and ri (i = 0, . . . , m + 1) such that
- r0 = e
- r1 = a
- rm = Δ
- rm+1 = 0
- and ri - 1 = ri*qi + ri + 1, 0 < ri + 1 < ri.
-
Further, there are integers si, ti with |ti| < e/ri - 1 and |si| < a/ri - 1 satisfying sie + ati = ri , (i = 2, . . . , m + 1).
-
Set μi = gcd(ti, ri) and t'i = ti/μi (i = 0, . . . , m + 1).
-
Let e > n/c, where c is an integer ≥ 1, and k = (ed−1)/ϕ(n).
-
Suppose that k or e−k is ≤ e0.25/6c0.5. Then, we have
- Δ < e3/4.
- k = |t'j| and p+q = (a +|t'j|-1) mod e, where j is such that rj is the largest remainder < e3/4.
- Or k = e − |t'j| and p + q = (a + (e − |t'j|) −1 ) mod e, where j is such that rj is the largest remainder < e3/4.
Input: An RSA public key (n, e) with e > n/c (Read the paper for more info about c). Output: The primes p and q.
- Compute a = (n + 1) mod e.
- Using the extended Euclidean algorithm for e and a, compute the biggest remainder rj among them which are < e3/4 and the associated integers sj , tj such that sje + atj = rj.
- Compute μj = gcd(tj , rj) and next t'j = tj/μj.
- Compute B1 = (a + |t'j|-1) mod e and next the solutions u1 and v1 of equation [X2 + B1X + n = 0]. If u1 and v1 are positive integers, then output (u1 , v1). Otherwise, go to the next step.
- Compute B2 = (a + (e − |t'j|)-1) mod e and next the solutions u2 and v2 of equation [X2 + B2X + n = 0]. If u2 and v2 are positive integers, then output (u2 , v2). Otherwise, output FAIL.
Poulakis, Dimitrios. (2020). An application of Euclidean algorithm in cryptanalysis of RSA. Elemente der Mathematik. 75. 114-120. 10.4171/EM/411.