-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daf97e9
commit 09eff49
Showing
2 changed files
with
91 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/de/tilman_neumann/jml/squareSums/FourSquaresFinderRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. | ||
* Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program; | ||
* if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.tilman_neumann.jml.squareSums; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.math.BigInteger; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.LogManager; | ||
|
||
import de.tilman_neumann.util.ConfigUtil; | ||
import de.tilman_neumann.util.Timer; | ||
|
||
/** | ||
* Runs the FourSquaresFinder. | ||
* | ||
* @author Tilman Neumann | ||
*/ | ||
public class FourSquaresFinderRunner { | ||
private static final Logger LOG = LogManager.getLogger(FourSquaresFinderRunner.class); | ||
|
||
// Some test numbers: | ||
// RSA-100 = 1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139 | ||
// RSA-576 = 188198812920607963838697239461650439807163563379417382700763356422988859715234665485319060606504743045317388011303396716199692321205734031879550656996221305168759307650257059 | ||
// RSA-768 = 1230186684530117755130494958384962720772853569595334792197322452151726400507263657518745202199786469389956474942774063845925192557326303453731548268507917026122142913461670429214311602221240479274737794080665351419597459856902143413 | ||
// RSA-1024 = 135066410865995223349603216278805969938881475605667027524485143851526510604859533833940287150571909441798207282164471551373680419703964191743046496589274256239341020864383202110372958725762358509643110564073501508187510676594629205563685529475213500852879416377328533906109750544334999811150056977236890927563 | ||
// RSA-1536 = 1847699703211741474306835620200164403018549338663410171471785774910651696711161249859337684305435744585616061544571794052229717732524660960646946071249623720442022269756756687378427562389508764678440933285157496578843415088475528298186726451339863364931908084671990431874381283363502795470282653297802934916155811881049844908319545009848393775227257052578591944993870073695755688436933812779613089230392569695253261620823676490316036551371447913932347169566988069 | ||
// RSA-2048 = 25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784406918290641249515082189298559149176184502808489120072844992687392807287776735971418347270261896375014971824691165077613379859095700097330459748808428401797429100642458691817195118746121515172654632282216869987549182422433637259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133844143603833904414952634432190114657544454178424020924616515723350778707749817125772467962926386356373289912154831438167899885040445364023527381951378636564391212010397122822120720357 | ||
// | ||
// Bit lengths of p: (modPow won't use intrinsics if the modulus is bigger than 512 ints = 16384 bit) | ||
// RSA-100: 2280 bit | ||
// RSA-576: 3988 bit | ||
// RSA-768: 5326 bit | ||
// RSA-1024: 7122 bit | ||
// RSA-1536: 10702 bit | ||
// RSA-2048: 14228 bit | ||
// | ||
// Sample test results (timings from single-threaded computation on a Ryzen 3900X): | ||
// RSA-100: 547 iterations, 3.2s -> 5.8 ms / iteration | ||
// RSA-576: 1418 iterations, 34s -> 23.9 ms / iteration | ||
// RSA-768: 201 iterations, 14s -> 69.6 ms / iteration | ||
// RSA-1024: 410 iterations, 98s -> 239.0 ms / iteration | ||
// RSA-1536: 1137 iterations, 522s -> 459.1 ms / iteration | ||
// RSA-2048: 4952 iterations, 5810s -> 1173.2 ms / iteration | ||
// | ||
// The four squares found for RSA-2048 are | ||
// 139358622875406229826194632018168725913863530524084728824959488637125391433486791229336098116125142097237531414910347448667794283543119738714123123604439331835321862872128682525681920365382964567979293371031694710495774753084738594661267677915725015647100758573715100114594987558150657046428842612575988986504^2 | ||
// + 56645192124943188273360503680632254768765084904484205988162052324689294883873799138603283417877164350515389553765514641396788129474127480877073799356177032509308457169554404027041358893058772366570490396634165954031047503762885945932388182828166576640161853104274288604094522205677897399922588225368981443591^2 | ||
// + 49898928610399351549386170211056897660544982371145285912063115590143130755557928852511643561935591744079175205297194858724484390362238872321630834030289818959547915890357505757296287563083790820413644514676011422795638660351803533794781466036112123303841618470172233509707609137763184579955351997121345985868^2 | ||
// + 8746532946873304713456658908072998216597594448035546491022766373486361520913105876767792923319305785665792251644616207234977646019586113983213940156948347600992725849219322512620971533949532103096661858381274646090409200410141949113998136460063270010295266885631080273377218330336473250356475586970093083306^2 | ||
public static void main(String[] args) { | ||
ConfigUtil.initProject(); | ||
while(true) { | ||
try { | ||
LOG.info("Please insert the number to decompose:"); | ||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | ||
String line = in.readLine(); | ||
String input = line !=null ? line.trim() : ""; | ||
//LOG.debug("input = >" + input + "<"); | ||
BigInteger N = new BigInteger(input); | ||
LOG.info("Searching four squares of " + N + " (" + N.bitLength() + " bits)..."); | ||
Timer timer = new Timer(); | ||
FourSquaresFinder fsf = new FourSquaresFinder(); | ||
fsf.find(N); | ||
long duration = timer.totalRuntime(); | ||
BigInteger[] result = fsf.getSquareBases(); | ||
LOG.info("Found 4 squares representation " + N + " = " + result[0] + "^2 + " + result[1] + "^2 + " + result[2] + "^2 + " + result[3] + "^2"); | ||
LOG.info("The computation needed " + fsf.getNumberOfIterations() + " iterations and took " + duration + "ms"); | ||
if (FourSquaresFinder.ANALYZE) { | ||
LOG.info("Phase timings: " + fsf.getPhaseTimings()); | ||
LOG.info("Step 2 subtimings: " + fsf.getStep2Subtimings()); | ||
} | ||
} catch (Exception ex) { | ||
LOG.error("Error " + ex, ex); | ||
} | ||
} | ||
} | ||
} |