Skip to content

Commit

Permalink
Iron out some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Nov 8, 2023
1 parent 61b38cc commit 5433755
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src_number/TestQuadraticResidue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void process(int TheMod) {
for (int u=0; u<TheMod; u++) {
T u_T(u);
bool test = is_quadratic_residue(u_T, TheMod_T);
if (test > 0) {
std::cerr << "u=" << u << " test=" << test << "\n";
if (test) {
n_quad += 1;
}
}
Expand All @@ -37,8 +38,8 @@ int main(int argc, char *argv[]) {
int TheMod = 23;
process<mpz_class>(TheMod);
process<SafeInt64>(TheMod);
process<boost::multiprecision::cpp_int>(TheMod);
process<boost::multiprecision::mpz_int>(TheMod);
// process<boost::multiprecision::cpp_int>(TheMod);
// process<boost::multiprecision::mpz_int>(TheMod);
std::cerr << "Normal termination of the program\n";
} catch (TerminalException const &e) {
std::cerr << "Somethng went wrong in the computation\n";
Expand Down
9 changes: 6 additions & 3 deletions src_number/quadratic_residue.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ std::optional<T> find_quadratic_residue(T const& a, T const& m_in) {
static_assert(is_implementation_of_Z<T>::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) {
Expand All @@ -26,14 +26,17 @@ std::optional<T> 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 {};
}
Expand Down

0 comments on commit 5433755

Please sign in to comment.