cangrepp

Some cryptographic attacks
Log | Files | Refs | README

hnpsolve.c (1228B)


      1 #include <flint.h>
      2 #include <fmpz_vec.h>
      3 #include <hnp.h>
      4 #include <stdio.h>
      5 #include <stdlib.h>
      6 
      7 #include <fmpzio.h>
      8 
      9 static int
     10 read_stdin_instance(fmpz **a, fmpz **t, slong *m, fmpz_t *B, fmpz_t *n)
     11 {
     12   flint_scanf("%wd", m);
     13 
     14   if (read_next_fmpz(*B))
     15     return -1;
     16 
     17   if (read_next_fmpz(*n))
     18     return -1;
     19 
     20   *a = _fmpz_vec_init(*m);
     21   *t = _fmpz_vec_init(*m);
     22 
     23   slong i;
     24   int fail = 0;
     25   for (i = 0; i < *m; i++) {
     26     if (read_next_fmpz(&(*t)[i])) {
     27       fail = 1;
     28       break;
     29     }
     30 
     31     if (read_next_fmpz(&(*a)[i])) {
     32       fail = 1;
     33       break;
     34     }
     35   }
     36 
     37   if (fail) {
     38     _fmpz_vec_clear(*a, *m);
     39     _fmpz_vec_clear(*t, *m);
     40     return -1;
     41   }
     42 
     43   return 0;
     44 }
     45 
     46 int
     47 main(int argc, char *argv[])
     48 {
     49   slong m;
     50   fmpz *a;
     51   fmpz *t;
     52   fmpz_t B, n;
     53   fmpz_init(B);
     54   fmpz_init(n);
     55 
     56   if (read_stdin_instance(&a, &t, &m, &B, &n) != 0) {
     57     fprintf(stderr, "ERROR! Bad input format?\n");
     58     exit(1);
     59   }
     60 
     61   fmpz res[m + 1];
     62   slong i;
     63   for (i = 0; i < m + 1; i++)
     64     fmpz_init(&res[i]);
     65 
     66   int ret = hidden_number_problem(res, m + 1, t, a, m, n, B);
     67   if (ret == 0) {
     68     for (i = 0; i < m; i++) {
     69       fmpz_print(&res[i]);
     70       printf(" ");
     71     }
     72     fmpz_print(&res[m]);
     73     printf("\n");
     74   }
     75 
     76   return 0;
     77 }