Exemplo n.º 1
0
/**
   @brief Test sieve by checking if function returns correct vector.

   @param A              input lattice
   @param b              shortest vector
   @return
*/
template <class ZT> int test_sieve_alg(ZZ_mat<ZT> &A, IntVect &b, int alg)
{
  GaussSieve<ZT, FP_NR<double>> gsieve(A, alg, 0, 0);
  Z_NR<ZT> goal_norm;
  goal_norm = 0;
  gsieve.set_goal_norm2(goal_norm);
  if (gsieve.alg == 3)
    gsieve.run_3sieve();
  else if (gsieve.alg == 4)
    gsieve.run_4sieve();
  else
    gsieve.run_2sieve();
  NumVect<Z_NR<ZT>> v = gsieve.return_first();
  Z_NR<ZT> tmp;
  Z_NR<ZT> norm_s;
  Z_NR<ZT> norm_b;
  for (int i = 0; i < A.get_cols(); i++)
  {
    tmp.mul(v[i], v[i]);
    norm_s.add(norm_s, tmp);
    tmp.mul(b[i], b[i]);
    norm_b.add(norm_b, tmp);
  }
  if (norm_s != norm_b)
    return 1;
  return 0;
}
Exemplo n.º 2
0
template <class ZT> int test_svp(ZZ_mat<ZT> &A, IntVect &b)
{
  IntVect sol_coord;   // In the LLL-reduced basis
  IntVect sol_coord2;  // In the initial basis
  IntVect solution;
  IntMatrix u;

  int status =
      lll_reduction(A, u, LLL_DEF_DELTA, LLL_DEF_ETA, LM_WRAPPER, FT_DEFAULT, 0, LLL_DEFAULT);
  if (status != RED_SUCCESS)
  {
    cerr << "LLL reduction failed: " << get_red_status_str(status) << endl;
    return status;
  }

  status = shortest_vector(A, sol_coord, SVPM_PROVED, SVP_DEFAULT);

  if (status != RED_SUCCESS)
  {
    cerr << "Failure: " << get_red_status_str(status) << endl;
    return status;
  }

  vector_matrix_product(sol_coord2, sol_coord, u);
  vector_matrix_product(solution, sol_coord, A);

  Z_NR<ZT> tmp;
  Z_NR<ZT> norm_s;
  Z_NR<ZT> norm_b;

  for (int i = 0; i < A.get_cols(); i++)
  {
    tmp.mul(solution[i], solution[i]);
    norm_s.add(norm_s, tmp);

    tmp.mul(b[i], b[i]);
    norm_b.add(norm_b, tmp);
  }
  if (norm_s != norm_b)
    return 1;

  return 0;
}