MTToolBox  0.2.10
AlgorithmRecursionSearch.hpp
Go to the documentation of this file.
1 #ifndef MTTOOLBOX_ALGORITHM_RECURSION_SEARCH_HPP
2 #define MTTOOLBOX_ALGORITHM_RECURSION_SEARCH_HPP
3 
28 #if defined(DEBUG)
29 #include <iostream>
30 #endif
31 #include <NTL/GF2X.h>
32 #include <NTL/GF2XFactoring.h>
35 #include <MTToolBox/period.hpp>
36 #include <MTToolBox/util.hpp>
37 
38 namespace MTToolBox {
39  using namespace std;
73  template<typename U, typename V = U>
75  public:
103  AbstractGenerator<V>& bg) {
104  rand = &generator;
105  baseGenerator = &bg;
106  count = 0;
108  }
109 
139  const AlgorithmPrimitivity& primitivity) {
140  rand = &generator;
141  baseGenerator = &bg;
142  count = 0;
143  isPrime = &primitivity;
144  }
145 
176  bool start(int try_count) {
177  long size = rand->bitSize();
178  long degree;
179  for (int i = 0; i < try_count; i++) {
180  rand->setUpParam(*baseGenerator);
181  rand->seed(getOne<U>());
182  minpoly(poly, *rand);
183  count++;
184  degree = deg(poly);
185  if (degree != size) {
186 #if defined(DEBUG)
187  cout << "degree:" << degree << endl;
188 #endif
189  continue;
190  }
191  if ((*isPrime)(size, poly)) {
192  return true;
193  }
194  }
195  return false;
196  }
197 
212  const std::string getParamString() {
213  return rand->getParamString();
214  }
215 
235  const NTL::GF2X& getMinPoly() const {
236  return poly;
237  }
238 
250  long getCount() const {
251  return count;
252  }
253 
254  private:
256  AbstractGenerator<V> *baseGenerator;
258  NTL::GF2X poly;
259  long count;
260  };
261 }
262 #endif // MTTOOLBOX_ALGORITHM_RECURSION_SEARCH_HPP
void minpoly(NTL::GF2X &poly, AbstractGenerator< U > &generator, int pos=0, int stateSize=0)
Calculate minimal polynomial of output sequence.
Definition: period.hpp:56
Algorithm which check if given polynomial is primitive.
Definition: AlgorithmPrimitivity.hpp:42
AlgorithmRecursionSearch(RecursionSearchable< U, V > &generator, AbstractGenerator< V > &bg)
Constructor Size of internal state is supposed to be Mersenne Exponent.
Definition: AlgorithmRecursionSearch.hpp:102
const AlgorithmPrimitivity MersennePrimitivity
An algorithm which checks if given polynomial is a primitive polynomial of given degree for pseudo ra...
const std::string getParamString()
Returns a string which shows parameters of pseudo random Call this method only after start() returns ...
Definition: AlgorithmRecursionSearch.hpp:212
Search parameters of state transition function of pseudo random number generator so that the characte...
Definition: AlgorithmRecursionSearch.hpp:74
long getCount() const
Returns tried count from the instance was created.
Definition: AlgorithmRecursionSearch.hpp:250
const NTL::GF2X & getMinPoly() const
Returns a minimal polynomial of output of the pseudo random number generator.
Definition: AlgorithmRecursionSearch.hpp:235
AlgorithmRecursionSearch(RecursionSearchable< U, V > &generator, AbstractGenerator< V > &bg, const AlgorithmPrimitivity &primitivity)
Constructor Users can specify algorithm of primitivity judgement.
Definition: AlgorithmRecursionSearch.hpp:137
Utility functions.
Abstract class for searching parameters of state transition function of pseudo random number generato...
Definition: RecursionSearchable.hpp:43
This file provides functions calculating minimal polynomials and checking primitivity.
Primitivity test.
bool isPrime(const NTL::GF2X &poly)
Check if polynomial is primitive.
bool start(int try_count)
Start searching recursion parameters.
Definition: AlgorithmRecursionSearch.hpp:176
name space for MTToolBox