Example #1
0
template <> int hkz(Options &o, ZZ_mat<mpz_t> &b)
{
  const char *format = o.output_format ? o.output_format : "b";
  int flags          = 0;
  if (o.verbose)
    flags |= HKZ_VERBOSE;
  string dump_gso_filename;
  if (o.bkz_flags & BKZ_DUMP_GSO) {
    dump_gso_filename = o.bkz_dump_gso_filename;
    flags |= BKZ_DUMP_GSO;
  }
  
  //int status = hkz_reduction(b, flags, o.float_type, o.precision, dump_gso_filename);
  int status = hkz_reduction(b, flags, o.float_type, o.precision);
  for (int i = 0; format[i]; i++)
  {
    if (format[i] == 'b')
    {
      if (format[i + 1] == 'k')
      {
        b.print_comma(cout);
        i++;
      }
      else
        cout << b << endl;
    }
  }
  if (status != RED_SUCCESS)
  {
    cerr << "Failure: " << get_red_status_str(status) << endl;
  }
  return status;
}
Example #2
0
template <class ZT> int lll(Options &o, ZZ_mat<ZT> &b)
{
  ZZ_mat<ZT> u, u_inv;
  const char *format = o.output_format ? o.output_format : "b";
  int status, flags = 0;
  if (o.verbose)
    flags |= LLL_VERBOSE;
  if (o.early_red)
    flags |= LLL_EARLY_RED;
  if (o.siegel)
    flags |= LLL_SIEGEL;

  if (strchr(format, 'v') != NULL)
  {
    // LLL-reduction with transform and inverse transform
    status = lll_reduction(b, u, u_inv, o.delta, o.eta, o.method, o.float_type, o.precision, flags);
  }
  else if (strchr(format, 'u') != NULL)
  {
    // LLL-reduction with transform
    status = lll_reduction(b, u, o.delta, o.eta, o.method, o.float_type, o.precision, flags);
  }
  else
  {
    status = lll_reduction(b, o.delta, o.eta, o.method, o.float_type, o.precision, flags);
  }

  for (int i = 0; format[i]; i++)
  {
    switch (format[i])
    {
    case 'b':
      cout << b << endl;
      break;
    case 'u':
      cout << u << endl;
      break;
    case 'v':
      cout << u_inv << endl;
      break;
    case 't':
      cout << status << endl;
      break;
    case ' ':
      cout << endl;
      break;
    }
  }
  if (status != RED_SUCCESS)
  {
    cerr << "Failure: " << get_red_status_str(status) << endl;
  }
  return status;
}
Example #3
0
template <> int bkz(Options &o, IntMatrix &b)
{
  CHECK(o.block_size > 0, "Option -b is missing");
  vector<Strategy> strategies;
  if (!o.bkz_strategy_file.empty())
  {
    strategies = load_strategies_json(strategy_full_path(o.bkz_strategy_file));
  }

  BKZParam param(o.block_size, strategies);
  IntMatrix u;
  const char *format = o.output_format ? o.output_format : "b";
  int status;

  param.delta = o.delta;
  param.flags = o.bkz_flags;

  if (o.bkz_flags & BKZ_DUMP_GSO)
    param.dump_gso_filename = o.bkz_dump_gso_filename;
  if (o.bkz_flags & BKZ_GH_BND)
    param.gh_factor = o.bkz_gh_factor;
  if (o.bkz_flags & BKZ_MAX_LOOPS)
    param.max_loops = o.bkz_max_loops;
  if (o.verbose)
    param.flags |= BKZ_VERBOSE;
  if (o.no_lll)
    param.flags |= BKZ_NO_LLL;

  status = bkz_reduction(&b, strchr(format, 'u') ? &u : NULL, param, o.float_type, o.precision);

  for (int i = 0; format[i]; i++)
  {
    switch (format[i])
    {
    case 'b':
      cout << b << endl;
      break;
    case 'u':
      cout << u << endl;
      break;
    case 't':
      cout << status << endl;
      break;
    case ' ':
      cout << endl;
      break;
    }
  }
  if (status != RED_SUCCESS)
  {
    cerr << "Failure: " << get_red_status_str(status) << endl;
  }
  return status;
}
Example #4
0
template <> int hkz(Options &o, ZZ_mat<mpz_t> &b)
{
  int flags = 0;
  if (o.verbose)
    flags |= HKZ_VERBOSE;
  int status = hkz_reduction(b, flags, o.float_type, o.precision);
  cout << b << endl;
  if (status != RED_SUCCESS)
  {
    cerr << "Failure: " << get_red_status_str(status) << endl;
  }
  return status;
}
Example #5
0
template <> int svpcvp(Options &o, ZZ_mat<mpz_t> &b, const vector<Z_NR<mpz_t>> &target)
{
  const char *format = o.output_format ? o.output_format : "s";
  IntVect sol_coord;    // In the LLL-reduced basis
  IntVect sol_coord_2;  // In the initial basis
  IntVect solution;
  IntMatrix u;
  bool with_coord     = strchr(format, 'c') != NULL;
  bool with_coord_std = strchr(format, 's') != NULL;
  int flags           = SVP_DEFAULT | (o.verbose ? SVP_VERBOSE : 0);
  int flagsLLL        = LLL_DEFAULT | (o.verbose ? LLL_VERBOSE : 0);
  int status;

  if (!o.no_lll)
  {
    if (with_coord)
    {
      status = lll_reduction(b, u, LLL_DEF_DELTA, LLL_DEF_ETA, LM_WRAPPER, FT_DEFAULT, 0, flagsLLL);
    }
    else
    {
      status = lll_reduction(b, LLL_DEF_DELTA, LLL_DEF_ETA, LM_WRAPPER, FT_DEFAULT, 0, flagsLLL);
    }
    if (status != RED_SUCCESS)
    {
      cerr << "LLL reduction failed: " << get_red_status_str(status) << endl;
      return status;
    }
  }

  if (target.empty())
    status = shortest_vector(b, sol_coord, SVPM_PROVED, flags);
  else
    status = closest_vector(b, target, sol_coord, flags);

  if (status != RED_SUCCESS)
  {
    cerr << "Failure: " << get_red_status_str(status) << endl;
    return status;
  }
  if (with_coord)
  {
    if (o.no_lll)
      sol_coord_2 = sol_coord;
    else
      vector_matrix_product(sol_coord_2, sol_coord, u);
  }
  if (with_coord_std)
  {
    vector_matrix_product(solution, sol_coord, b);
  }

  for (int i = 0; format[i]; i++)
  {
    switch (format[i])
    {
    case 'c':
      cout << sol_coord_2 << endl;
      break;
    case 's':
      cout << solution << endl;
      break;
    case 't':
      cout << status << endl;
      break;
    case ' ':
      cout << endl;
      break;
    }
  }
  return status;
}