From 5433755dba31981d2912eb6c0384be3e15011c7e Mon Sep 17 00:00:00 2001 From: Mathieu Dutour Sikiric Date: Wed, 8 Nov 2023 10:26:51 +0100 Subject: [PATCH] Iron out some bugs. --- src_number/TestQuadraticResidue.cpp | 7 ++++--- src_number/quadratic_residue.h | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src_number/TestQuadraticResidue.cpp b/src_number/TestQuadraticResidue.cpp index fb32cdb..78960a0 100644 --- a/src_number/TestQuadraticResidue.cpp +++ b/src_number/TestQuadraticResidue.cpp @@ -17,7 +17,8 @@ void process(int TheMod) { for (int u=0; u 0) { + std::cerr << "u=" << u << " test=" << test << "\n"; + if (test) { n_quad += 1; } } @@ -37,8 +38,8 @@ int main(int argc, char *argv[]) { int TheMod = 23; process(TheMod); process(TheMod); - process(TheMod); - process(TheMod); + // process(TheMod); + // process(TheMod); std::cerr << "Normal termination of the program\n"; } catch (TerminalException const &e) { std::cerr << "Somethng went wrong in the computation\n"; diff --git a/src_number/quadratic_residue.h b/src_number/quadratic_residue.h index 55719a8..fb4b0d7 100644 --- a/src_number/quadratic_residue.h +++ b/src_number/quadratic_residue.h @@ -14,7 +14,7 @@ std::optional find_quadratic_residue(T const& a, T const& m_in) { static_assert(is_implementation_of_Z::value, "Requires T to be a Z ring"); T m = T_abs(m_in); T two(2); - T a_mod = QuoInt(a, m); + T a_mod = ResInt(a, m); T res = ResInt(m, two); T upper(0); if (res == 0) { @@ -26,14 +26,17 @@ std::optional find_quadratic_residue(T const& a, T const& m_in) { T x(0); T TwoXpOne(1); T xSqr(0); + // std::cerr << "m=" << m << " a=" << a << " a_mod=" << a_mod << "\n"; while (x != upper) { + // std::cerr << " x=" << x << " xSqr=" << xSqr << "\n"; if (xSqr == a_mod) { + // std::cerr << "Returning x=" << x << "\n"; return x; } xSqr += TwoXpOne; - xSqr = QuoInt(xSqr, m); + xSqr = ResInt(xSqr, m); TwoXpOne += 2; - x += 2; + x += 1; } return {}; }