3688eb75 |
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | |
4 | #include "rand.h" |
5 | #include "group.h" |
6 | #include "gfreduce.h" |
7 | |
8 | int main(int argc, char *argv[]) |
9 | { |
10 | mp *p, *q, *g, *gg, *t, *h; |
11 | gfreduce r; |
12 | group *grp; |
13 | gbin_param gb; |
14 | const char *e; |
15 | int i; |
16 | |
17 | t = MP_NEW; |
18 | q = mp_readstring(MP_NEW, argv[1], 0, 0); |
19 | p = MP_ZERO; |
20 | for (i = 2; i < argc; i++) { |
21 | t = mp_lsl(t, MP_ONE, atoi(argv[i])); |
22 | p = mp_add(p, p, t); |
23 | } |
24 | gfreduce_create(&r, p); |
25 | t = mp_lsl(t, MP_ONE, mp_bits(p) - 1); |
26 | t = mp_sub(t, t, MP_ONE); |
27 | h = MP_NEW; |
28 | mp_div(&h, &t, t, q); |
29 | assert(MP_ZEROP(t)); |
30 | g = MP_NEW; |
31 | gg = MP_TWO; |
32 | for (;;) { |
33 | g = gfreduce_exp(&r, g, gg, h); |
34 | t = gfreduce_exp(&r, t, g, q); |
35 | if (MP_EQ(t, MP_ONE) && !MP_EQ(g, MP_ONE)) { |
36 | gb.p = p; |
37 | gb.q = q; |
38 | gb.g = g; |
39 | grp = group_binary(&gb); |
40 | assert(grp); |
41 | if ((e = G_CHECK(grp, &rand_global)) != 0) { |
42 | fprintf(stderr, "badness: %s\n", e); |
43 | exit(1); |
44 | } |
45 | fputs(" p 0x", stdout); |
46 | mp_writefile(p, stdout, 16); |
47 | putchar('\n'); |
48 | fputs(" q 0x", stdout); |
49 | mp_writefile(q, stdout, 16); |
50 | putchar('\n'); |
51 | fputs(" g 0x", stdout); |
52 | mp_writefile(g, stdout, 16); |
53 | putchar('\n'); |
54 | return (0); |
55 | } |
56 | gg = mp_add(gg, gg, MP_ONE); |
57 | } |
58 | } |