-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmtgp32-calc-poly.cpp
More file actions
133 lines (126 loc) · 3.06 KB
/
Copy pathmtgp32-calc-poly.cpp
File metadata and controls
133 lines (126 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* @file mtgp32-calc-poly.cpp
*
* @brief calculate characteristic polynomial for 32bit mtgp.
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (Hiroshima University)
*
* Copyright (c) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima
* University and University of Tokyo. All rights reserved.
*
* The new BSD License is applied to this software, see LICENSE.txt
*/
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <string>
#include <errno.h>
#include <NTL/GF2X.h>
#include <NTL/vec_GF2.h>
#include <NTL/GF2XFactoring.h>
#include "mtgp32-calc-poly.hpp"
#include "mtgp-calc-jump.hpp"
#include "mtgp32-fast.h"
using namespace std;
using namespace NTL;
/**
* calculate the characteristic polynomial for given 32-bit MTGP.
* MinPolySeq is defined in NTL.
* @param[out] poly calculated characteristic polynomial.
* @param[in] mtgp64 generator
*/
void calc_characteristic(GF2X& poly, mtgp32_fast_t * mtgp32)
{
vec_GF2 seq;
int mexp = mtgp32->params.mexp;
seq.SetLength(2 * mexp);
for (int i = 0; i < 2 * mexp; i++) {
seq[i] = mtgp32_genrand_uint32(mtgp32) & 1;
}
MinPolySeq(poly, seq, mexp);
}
/**
* calculate the characteristic polynomial for given 32-bit MTGP.
* MinPolySeq is defined in NTL.
* @param[out] str calculated characteristic polynomial in string format.
* @param[in] mtgp64 generator
*/
void calc_characteristic(string& str, mtgp32_fast_t * mtgp32)
{
GF2X poly;
calc_characteristic(poly, mtgp32);
polytostring(str, poly);
}
void calc_characteristic(uint32_t array[], int size, mtgp32_fast_t * mtgp32)
{
GF2X poly;
calc_characteristic(poly, mtgp32);
polytoarray(array, size, poly);
}
#if defined(MAIN)
/**
* main function for executable.
* @param[in] argc number of arguments.
* @param[in] argv an array of arguments.
* @return 0 if normal, other abnormal.
*/
int main(int argc, char *argv[]) {
int mexp;
int no;
uint32_t seed = 1;
mtgp32_params_fast_t *params;
mtgp32_fast_t mtgp32;
int rc;
if (argc <= 2) {
printf("%s: mexp no.\n", argv[0]);
return 1;
}
mexp = strtol(argv[1], NULL, 10);
if (errno) {
printf("%s: mexp no.\n", argv[0]);
return 2;
}
no = strtol(argv[2], NULL, 10);
if (errno) {
printf("%s: mexp no.\n", argv[0]);
return 3;
}
switch (mexp) {
case 11213:
params = mtgp32_params_fast_11213;
break;
case 23209:
params = mtgp32_params_fast_23209;
break;
case 44497:
params = mtgp32_params_fast_44497;
break;
default:
printf("%s: mexp no.\n", argv[0]);
printf("mexp shuould be 11213, 23209 or 44497\n");
return 4;
}
if (no >= 128 || no < 0) {
printf("%s: mexp no.\n", argv[0]);
printf("no must be between 0 and 127\n");
return 5;
}
params += no;
rc = mtgp32_init(&mtgp32, params, seed);
if (rc) {
printf("failure in mtgp32_init\n");
return -1;
}
mtgp32_print_idstring(&mtgp32, stdout);
#if 0
string s;
calc_characteristic(s, &mtgp32);
printf("%s\n", s.c_str());
#else
#endif
mtgp32_free(&mtgp32);
return 0;
}
#endif