Bill Allombert on Mon, 09 Oct 2023 15:36:42 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: efficient foursquare() and/or threesquare1m4() functions
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: efficient foursquare() and/or threesquare1m4() functions
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Mon, 9 Oct 2023 15:36:11 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1696858583; c=relaxed/relaxed; bh=7Z0MvUthB7ckSwveJYHgKG/uOZ3mGarAEnusXbrxzc0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=DZNvTdlsDX5Xxuv8ucCZjS8B/aHkXxjhcaasgqU96hR0FCLSIZYOgYF3Cat+CROmF+lEpk8W6binjhTnS2f0D4BUfjlCsb1H2XARaG/scNzXOGk2CGMel/LKzoQc6L+u17ChzYkpo9T2/F/oPmJaHUgQc/4MDMh1XaynQkdI4e5KqVcGljReD8BmsUnmZnPDOG6YqhgMmd0R8JBrRGH+ZhFmtVYlBG5o1El3t7VeZccZ0rZSy2pNoBA0QyOKDgjnuyCuUmL9iEy7cK373wbF+7T/v+F0DXTPhW2rxV/1B3LaQ/7NcGyhbbI+cEwyYz/p8uVxl/pZ1x3KYmA2xEtHrbYRAlmNyhVQsQVbflUxsy7clCL2LOeAHCSYvLyPUV5dhboIgL1Yz5AnivRovwyWicE7yZfzz/3I2gXIOwcmuEad2uCUbrGCEqTcQCEl6zqtFwHIS6B2wv0MF1xMlRKvUqNoC4SSO+oe6ON0+oll9dEu6WCJAWLiBEu3Gq4czT2vRjKgrh3j5ayc1HJBrJNnAwUfP0StHL2pPQsq0tpwV2JRlA9oW1/SXlwBHYYr53WtkF+1Qk9QlBe5pFUumVqw1JNfTvPFiMunvy7s2Bs2KxLornZNn1DztL4ryqk8b9aW5Y3Wjs91sgOaTpreFjtIsz7UBe3NaC9EJa/sUZWpcd0=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1696858583; cv=none; b=jN4/R5SMsHg9P68SaC8sc7VqR1gIkRkoHhkaEb5GWQPPQJaBUulkJYhnYUPcumES1V6aDMCz7kB6Va4lPWdDKObaxOX8XYsnksQaWfuugR28TLeJeKHPIbFd63cSG0stEMc5oULPZLs4ObHu/dLDP+Ziu034PFdEjfuMEdz9raPL13MHKPempt99McVbH1G+8BI4jtZnxKNFoyqZUXwffGJiNBXO+kfUuCBh7Z7nodk9eKAQb/VIH1IkrHLdbBvLj9USSmxAioizP++sGZOCKOT6FzlhUBsEaH0QrMqiLXQ+Ije9/9g3MBz7HlZ7CQ4Iiqx/bpsHO2duApsl+fj68Uop3K/WsyI5JNESl6b586q9S8tuxW5DtHB1q124vy1myu3uWVc/o1SRkXAdcmIysl+6GcFC6XIAEM5Qx6s7RJiLqKX8OpO/u85HRqGaGALws2TmaOTbr6kVNN+3zqaiE7TP9HBssaqsxzIp4V5+KNaqSK6YlTPDy3OMLRSONk3+0AtwF7EXGcnTMSqwIe28+qPn81j10JmLikUPNKMFGRtUXofmVHM/Qhe1qOXFyCTT4auH6Q7+dgbo5gHVFSscgBoT4j45Qz+q4ZqF2k7MkDH2LHJ1efseeFKJ+r/YnRnEsjzxCR+md2K419r4JDxRuZd0r2B25vbUqkUFXNWeC8Y=
- Authentication-results: smail; arc=none
- Delivery-date: Mon, 09 Oct 2023 15:36:42 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1696858583; bh=7Z0MvUthB7ckSwveJYHgKG/uOZ3mGarAEnusXbrxzc0=; h=Date:From:To:Subject:References:In-Reply-To:From; b=VPA5yU8j6G2wmkGGsEfeR2u/TkuCBj1OYWNlqSFGAMiSTwIBY6JrUZkeym09VyggU 1ILRPjj2r0S2pb5SRD34zMPofsOwDLUfXUNiWRUjdABQBxWWDlJyvpMu0lC1m7OMsK 29FGFM0EK5AgIS+aGv7dUMuGP0AZ+L8AnKaI4HzRNWjkFofXKK+CxLna26E8sTbQHC jeGyX4GuBxwGqGltO8yKJbM7U200EF7SwFlkJMJVaYRZfD+1I48EleB1kE1sv0viZg jEFf4ROQmSURzrglMiI4QOyga83t/gWwxJAurXy3BtP3WizFa/sHofk89dq2g1vEGs ACjQe2oue9wJ+sWU9k4ls/VZVbzlq9EtigL7r6R6vVyAV9TQn6lQ9z8V94zNyQIinz YEcSxbUKT9okzzHtxrDM2r6FR24RlJqDLSbss8VTenkbsha2K7R+X5iBtcmtrHtoxi aWVXpHEcTXGnoxShIzY1wKI1xadnP7ErBH7SEjKOx11zMhUD9uWaaKaAMS5niH7p4j lm/fj/8lPxvYgsVvXsCy7zD6Q7f7Z875eLZQH+IpaNf04i8gvkIfNm5+2W0ih5ICfb pjybs7mt7NDU78HP5+6fBqvOGIWKRkPLhv4S4qVlz/Ty1iau4hlyMC6dPLel+b/OBn WxKQCm8WLjURXGiueVFL0q2s=
- In-reply-to: <497b843b2b3d6b57a6488664a1c13708@stamm-wilbrandt.de>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <d1c78430066dfb66eb8919b4cde59d9c@stamm-wilbrandt.de> <ZSLbBJaBWbGWnjT1@seventeen> <497b843b2b3d6b57a6488664a1c13708@stamm-wilbrandt.de>
On Mon, Oct 09, 2023 at 03:04:10PM +0200, hermann@stamm-wilbrandt.de wrote:
> Hi Bill,
>
> So wrong result for RSA-x with x in {129, 130, 155, 160, 640, 250}.
> Can you please look into this?
Indeed, I forgot a flag in twosquares (to allow imprimitive solutions)
I join a fixed version.
Cheers,
Bill
twosquares(n)=abs(qfbsolve(Qfb(1,0,1),n,2))
threesquares_fact(n)=abs(qfsolve(matdiagonal([1,1,1,-n]))[1..3])~
fouresquares_fact(n)=abs(qfsolve(matdiagonal([1,1,1,1,-n]))[1..4])~
isfact(n)=my(F=factor(n,2^20)[,1]);ispseudoprime(F[#F]);
threesquares(n)=
{
if(isfact(n),return(threesquares_fact(n)));
forstep(i=sqrtint(n),1,-1,
my(P=n-i^2,v = valuation(P,2), Q = P/2^v);
if(Q%4==1 && ispseudoprime(Q),return(concat(i,twosquares(P)))));
}
foursquares(n)=
{
if(isfact(n),return(foursquares_fact(n)));
forstep(i=sqrtint(n),1,-1,
my(P=n-i^2, v = valuation(P,2)\2);
if (P/4^v%8!=7,
my(F=factor(P,2^20)[,1]);
if(ispseudoprime(F[#F]),
return(concat(i,threesquares_fact(P))))));
}
test()=
{
my(P=randomprime(2^500,Mod(1,8))*randomprime(2^500,Mod(7,8)));
my(F=foursquares(P));
if (#F!=4 || norml2(F)!=P,error("foursquares",P));
my(P=randomprime(2^500,Mod(1,8))*randomprime(2^500,Mod(3,8)));
my(F=threesquares(P));
if (#F!=3 || norml2(F)!=P,error("threesquares",P));
my(P=4*randomprime(2^500,Mod(1,4)));
my(F=twosquares(P));
if (#F!=2 || norml2(F)!=P,error("twosquares",P));
}