Skip to content

Commit 1fdca4b

Browse files
Debug solveCongruence()
1 parent 0852e41 commit 1fdca4b

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88

99
[project]
1010
name = "FindAFactor"
11-
version = "5.1.0"
11+
version = "5.1.1"
1212
requires-python = ">=3.8"
1313
description = "Find any nontrivial factor of a number"
1414
readme = {file = "README.txt", content-type = "text/markdown"}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def build_extension(self, ext):
4040

4141
setup(
4242
name='FindAFactor',
43-
version='5.1.0',
43+
version='5.1.1',
4444
author='Dan Strano',
4545
author_email='stranoj@gmail.com',
4646
description='Find any nontrivial factor of a number',

0 commit comments

Comments
 (0)