@@ -855,26 +855,24 @@ struct Factorizer {
855855 BigInteger solveCongruence (const std::vector<size_t >& solutionVec)
856856 {
857857 // Compute x and y
858- BigInteger x = 1 ;
858+ BigInteger y = 1U ;
859859 for (size_t idx : solutionVec) {
860- x *= smoothNumberKeys[idx];
860+ y *= smoothNumberKeys[idx];
861861 }
862862 // If we square the result, it shouldn't ruin the fact
863863 // that the residue is a perfect square.
864- const BigInteger y = sqrt ((x * x ) % this ->toFactor );
864+ const BigInteger x = sqrt ((y * y ) % this ->toFactor );
865865
866866 // Check congruence of squares
867867 BigInteger factor = gcd (this ->toFactor , x + y);
868- if ((factor != 1U ) && (factor != this ->toFactor )) {
868+ if ((factor > 1U ) && (factor < this ->toFactor )) {
869869 return factor;
870870 }
871871
872- if (x != y) {
873- // Try x - y as well
874- factor = gcd (this ->toFactor , x - y);
875- if ((factor != 1U ) && (factor != this ->toFactor )) {
876- return factor;
877- }
872+ // Try x - y as well
873+ factor = gcd (this ->toFactor , x - y);
874+ if ((factor > 1U ) && (factor < this ->toFactor )) {
875+ return factor;
878876 }
879877
880878 // Failed to find a factor
@@ -987,7 +985,7 @@ struct Factorizer {
987985 GaussianEliminationResult result = gaussianElimination ();
988986 for (size_t i = 0U ; i < result.solutionColumns .size (); ++i) {
989987 const BigInteger factor = solveCongruence (findDependentRows (result, i));
990- if ((factor != 1U ) && (factor != toFactor)) {
988+ if ((factor > 1U ) && (factor < toFactor)) {
991989 return factor;
992990 }
993991 }
0 commit comments