MTToolBox  0.2.10
AlgorithmReducibleRecursionSearch.hpp
Go to the documentation of this file.
1 #ifndef MTTOOLBOX_ALGORITHM_REDUCIBLE_RECURSION_SEARCH_HPP
2 #define MTTOOLBOX_ALGORITHM_REDUCIBLE_RECURSION_SEARCH_HPP
3 
33 #if defined(DEBUG)
34 #include <iostream>
35 #endif
36 #include <NTL/GF2X.h>
37 #include <NTL/GF2XFactoring.h>
38 #include <MTToolBox/util.hpp>
41 #include <MTToolBox/period.hpp>
42 
43 namespace MTToolBox {
44  using namespace std;
45 
46  template<typename U, typename V = U>
47  void calcCharacteristicPolynomial(RecursionSearchable<U, V> *rand,
48  NTL::GF2X& poly);
83  template<typename U, typename V = U>
85  public:
113  AbstractGenerator<V>& bg) {
114  rand = &generator;
115  baseGenerator = &bg;
116  count = 0;
117  }
118 
122  bool start(int try_count) {
123  long degree;
124  long mexp = rand->getMexp();
125  for (int i = 0; i < try_count; i++) {
126  rand->setUpParam(*baseGenerator);
127  rand->seed(getOne<U>());
128 #if defined(DEBUG)
129  cout << "rand param:";
130  cout << rand->getParamString() << endl;
131 #endif
132  minpoly(poly, *rand);
133  irreducible = poly;
134  count++;
135  if (deg(irreducible) < mexp) {
136 #if defined(DEBUG)
137  cout << "irrepoly deg = " << deg(irreducible)
138  << " skip" << endl;
139 #endif
140  continue;
141  }
142  bool hasFactor = hasFactorOfDegree(irreducible, mexp);
143 #if defined(DEBUG)
144  cout << "has factor = " << hasFactor << endl;
145 #endif
146  if (!hasFactor) {
147 #if defined(DEBUG)
148  cout << "not has factor of degree irrepoly deg = "
149  << deg(irreducible) << " skip" << endl;
150 #endif
151  continue;
152  }
153  degree = deg(irreducible);
154  if (degree != mexp) {
155 #if defined(DEBUG)
156  cout << "degree:" << degree << "degree != mexp skip"
157  << endl;
158 #endif
159  continue;
160  }
161  return true;
162  }
163  return false;
164  }
165 
169  const std::string getParamString() {
170  return rand->getParamString();
171  }
172 
184  const NTL::GF2X& getCharacteristicPolynomial() {
185  return poly;
186  }
187 
203  const NTL::GF2X& getIrreducibleFactor() const {
204  return irreducible;
205  }
206 
218  long getCount() const {
219  return count;
220  }
221 
222  private:
224  AbstractGenerator<V> *baseGenerator;
225  NTL::GF2X poly;
226  NTL::GF2X irreducible;
227  long count;
228 
229  };
230 
251  template<typename U, typename V = U>
253  NTL::GF2X& poly)
254  {
255 #if defined(DEBUG)
256  cout << "calcCharacteristicPolynomial start" << endl;
257 #endif
258  int bitsize = bit_size<U>();
259  NTL::GF2X minpol;
260  NTL::GF2X lcmpoly = poly;
261  int size = rand->bitSize();
262  for (int i = 0; i < bitsize; i++) {
263  if (deg(lcmpoly) == size) {
264  poly = lcmpoly;
265 #if defined(DEBUG)
266  cout << "calcCharacteristicPolynomial end" << endl;
267 #endif
268  return;
269  }
270  minpoly(minpol, *rand, i);
271  LCM(lcmpoly, lcmpoly, minpol);
272  }
273  poly = lcmpoly;
274 #if defined(DEBUG)
275  cout << "calcCharacteristicPolynomial end" << endl;
276 #endif
277  }
278 }
279 #endif // MTTOOLBOX_ALGORITHM_REDUCIBLE_RECURSION_SEARCH_HPP
bool hasFactorOfDegree(NTL::GF2X &poly, long degree)
Check if primitive polynomial of given degree appears in factorization of poly.
AlgorithmReducibleRecursionSearch(ReducibleGenerator< U, V > &generator, AbstractGenerator< V > &bg)
Constructor Size of internal state is supposed to be power of 2 and larger than Mersenne Exponent...
Definition: AlgorithmReducibleRecursionSearch.hpp:112
void minpoly(NTL::GF2X &poly, AbstractGenerator< U > &generator, int pos=0, int stateSize=0)
Calculate minimal polynomial of output sequence.
Definition: period.hpp:56
virtual int bitSize() const =0
Return bit size of internal state, i.e dimension of GF(2)-vector space.
const std::string getParamString()
Returns a string which shows parameters of pseudo random Call this method only after start() returns ...
Definition: AlgorithmReducibleRecursionSearch.hpp:169
void calcCharacteristicPolynomial(RecursionSearchable< U, V > *rand, NTL::GF2X &poly)
const NTL::GF2X & getCharacteristicPolynomial()
Returns a minimal polynomial of output of the pseudo random number generator.
Definition: AlgorithmReducibleRecursionSearch.hpp:184
This class is an Abstract class for reducible generator.
Definition: ReducibleGenerator.hpp:57
Utility functions.
const NTL::GF2X & getIrreducibleFactor() const
Returns a maxmum irreducible factor of minimal polynomial of output of the pseudo random number gener...
Definition: AlgorithmReducibleRecursionSearch.hpp:203
Search parameters of state transition function of pseudo random number generator so that the characte...
Definition: AlgorithmReducibleRecursionSearch.hpp:84
long getCount() const
Returns tried count from the instance was created.
Definition: AlgorithmReducibleRecursionSearch.hpp:218
static void LCM(NTL::GF2X &lcm, const NTL::GF2X &x, const NTL::GF2X &y)
Calculate the Least Common Multiple of x and y.
Definition: util.hpp:509
This file provides functions calculating minimal polynomials and checking primitivity.
Primitivity test.
bool start(int try_count)
Start searching recursion parameters.
Definition: AlgorithmReducibleRecursionSearch.hpp:122
name space for MTToolBox