From the special form of p and q specified it can be determined that
the difference d= |p-q| is of the form k^2-1 with one exception.
Also d mod 24 = 0.
The exception is when a=b=1. In this case d = 1.
The limited number of unique differences significantly reduces the
factorization time.
Note that n is known but p,q,a, b and d are not. p and q are prime.
The difference d= |p-q| = |a^2+b^2-(2ab+1)| = |a^2+b^2-2ab-1|
This reduces to d=(a-b)^2-1.
With the difference d known the factors of n can be found by finding
integer solutions to the quadratic: p^2+dp-n = 0 which is a
rearrangement of p(p+d) = n.
The algorithm to factor n with this special form:
'RSA numbers usually have equal length factors
n_len = length(n) 'length in decimal digits
factor_len = round(n_len/2)
min_factor_value = 10^(factor_len-1)
max_factor_value = 10^(factor_len)-1
'm is the maximum possible difference between p and q
' Example for 4 digit factors m=9999-1000 = 8999
m = max_factor_value - min_factor_value
k =round(sqrt(m))
loop:
If k^2 mod 24 = 1
d = k^2-1
if (d^2+4n) is a square
p = (-d+sqrt(d^2+4n))/2
q = n/p
return p,q
k = k-1
goto loop
Benchmarked this algorithm in Pari/Gp versus the Fermat algorithm for
n, a random modulus of the special form requested.
n = 74234692929546985792914275827849
The algorithm above took 4.978 seconds.
Fermat's algorithm was still running after 49 minutes and 25 seconds and had not completed.
n is a random modulus of the special form requested.
p = a^2+b^2
q = 2ab+1
both p and q prime
After factoring n
p = 8622962252581529
q = 8608954875956081
d = 14007376625448
a = 67506520
b = 63763877
Hope this helps.