hermann on Fri, 25 Sep 2026 11:00:14 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

question on intersection of two primes discriminant search for qfb


It is well known that one can easily factor a semiprime if given two distinct sums of two squares:

pi@raspberrypi5:~/RSA_numbers_factored/pari $ gp -q RSA_numbers_factored.gp
? t=RSA.get(768); n=t[2]; [e,f]=RSA.square_sums(t);[a,b]=e;[c,d]=f;
? [(a^2+b^2)==n && (c^2+d^2)==n, #Set([a,b,c,d])]
[1, 4]
$

? p=gcd((a+c)^2+(b+d)^2,n); q=gcd((a+c)^2+(b-d)^2,n);
? [1<p && p<n && 1<q && q<n && n==p*q, #binary(n)]
[1, 768]
?

In lecture free period I worked Heidelberg University elementary number theory lecture from fall 2024 with videos, script and exercises. Followed by 53×30min youtube video lecture series "Berkeley math 115: Introduction to number theory",
here my summaries with link to youtube and my code examples:
https://github.com/Hermann-SW/uni-heidelberg/blob/main/markdown/Math155.md


I learned on quadratic binary forms in Berkley lecture, and thought on
generalization for sum of two squares approach shown above [which is Qfb(1,0,1)].

In a many hour chat with Gemini I was finally able to get working code,
and it is short and cleaner than all we had worked on in between.
In between was code with number fields, t_POL and finally qfbs.

Here is new function qfb_sums(), only 31 lines are result of the Gemini chat:
https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/pari/RSA_numbers_factored.gp#L241-L296

Any comments on that code with a loop through all negative discriminants aborting if conditions on determined qbfs for p and q are met are welcome (this email is for that).


Same factoring as above for recently factored RSA-896:

pi@raspberrypi5:~/RSA_numbers_factored/pari $ gp -q RSA_numbers_factored.gp
? t=RSA.get(896); n=t[2]; [D,Q,s1,s2]=RSA.qfb_sums(t);
? qfeval(Q,s1)==n && qfeval(Q,s2)==n
1
?

? p=gcd(qfeval(Q,s1+s2),n); 1<p && p<n && n%p==0
1
? ##
  ***   last result computed in 0 ms.
?


Really fast on cheap single board computer.

? foreach(RSA.factored(),t,my([l,n]=t);my([D,Q,s1,s2]=RSA.qfb_sums(t));\
my(p=gcd(qfeval(Q,s1+s2),n));print(l," ",D," ",Q," ",\
qfeval(Q,s1)==n&&qfeval(Q,s2)==n," ",1<p&&p<n&&n%p==0))
59 -4 Qfb(1, 0, 1) 1 1
79 -3 Qfb(1, 1, 1) 1 1
100 -68 Qfb(3, 2, 6) 1 1
110 -11 Qfb(1, 1, 3) 1 1
120 -24 Qfb(1, 0, 6) 1 1
129 -4 Qfb(1, 0, 1) 1 1
130 -11 Qfb(1, 1, 3) 1 1
140 -68 Qfb(3, 2, 6) 1 1
150 -11 Qfb(1, 1, 3) 1 1
155 -24 Qfb(1, 0, 6) 1 1
160 -43 Qfb(1, 1, 11) 1 1
170 -24 Qfb(1, 0, 6) 1 1
576 -40 Qfb(1, 0, 10) 1 1
180 -4 Qfb(1, 0, 1) 1 1
190 -24 Qfb(1, 0, 6) 1 1
640 -8 Qfb(1, 0, 2) 1 1
200 -20 Qfb(2, 2, 3) 1 1
210 -7 Qfb(1, 1, 2) 1 1
704 -24 Qfb(1, 0, 6) 1 1
220 -20 Qfb(1, 0, 5) 1 1
230 -4 Qfb(1, 0, 1) 1 1
232 -24 Qfb(1, 0, 6) 1 1
768 -4 Qfb(1, 0, 1) 1 1
240 -40 Qfb(1, 0, 10) 1 1
250 -19 Qfb(1, 1, 5) 1 1
260 -24 Qfb(1, 0, 6) 1 1
896 -11 Qfb(1, 1, 3) 1 1
? ##
  ***   last result computed in 7 ms.
?


For the 5 factored sofar RSA numbers that are product of two primes
=1 (mod 4) discriminant -4 with Qfb(1,0,1) are reported above:

? foreach(RSA.factored(mod4=[1,1]),t,print1(t[1]," "))
59 129 180 230 768
?


Regards,

Hermann.