# Chaos Based Cryptographic Pseudo-Random Number Generator Template with Dynamic State Change +
## 3 Generator Implementation and Testing  
### Testing Setup  
The experimental implementation done in C++ defines a _GeneratorTemplate_ template class that can be parameterized with a specific map function and an entropy builder. Four applications were developed for testing and evaluation:  
1. _generator_--an application that takes as arguments a byte count, the name of the map, the entropy builder, the number of iterations for time spacing and the initial state values and parameters and generates a text file with the specified number of bytes, one per line, in binary format;
2. _test_suite_--an application that takes as arguments the name of the map, the entropy builder, the number of iterations for time spacing and the initial state values and parameters and runs the _TestU101_ and _NIST_ test batteries, outputting the results in a corresponding file, and appending a summary to the results.csv file;
3. _throughput_test_--an application that takes as arguments a byte count, the name of the map, the entropy builder, the number of iterations for time spacing and the initial state values and parameters and computes the throughput of the specified generator in MB/s;
4. _codec_--an application that takes as arguments the name of the input PNG file, the name of the output PNG file, the name of the map, the entropy builder, the number of iterations for time spacing and the initial state values and parameters and encrypts (or decrypts, as the stream cipher is symmetric) the input image, writing the results in the output file. The _generator_ can be used to write pseudo-random data to a file for later use in other third party applications or test batteries, like _Diehard_[35]. For this section however, the relevant executables are _test_suite_ and _throughput_test_. The randomness statistical tests used to validate the generator are _TestU01_[36] running either _SmallCrush_, _Crush_ or _BigCrush_ suites and the _NIST_[14] test battery. _TestU01_ is installed in the system and dynamically linked to the testing application as opposed to the _NIST_ suite which is integrated at code level. The _NIST_ suite has also suffered minor code changes in order to strip down the test harness and run the tests directly. _TestU01_ is called using its own API which provides a simple and direct way of specifying a function to call in order to receive a new pseudo-random word. _NIST_ however required some additional work since all the tests are designed to read pseudo-random data from a file, so the testbench starts by generating all required data and writing it into a file and then calling _NIST_'s _asses_ function which in turn will invoke each test that will read pseudo-random data from the aforementioned file. NIST is configured to test 12 streams of 1 million bytes for each tested seed value. _TestU01_'s _SmallCrush_ is used in all tests presented in this paper. The entire testbench design is shown in Figure 6.  
Figure 6: Testbench block diagram. As a comparison with state-of-the art pRNGs, three algorithms were selected and tested along with the current system proposal:  
1. **Mersenne Twister--** a non-cryptographically secure pRNG, described in [37] and implemented in the GCC C++ standard library;
2. **ChaCha--**a cryptographically secure pRNG, from the stream cipher implementation in [38];
3. **Adaptive Chirikov Map pRNG--**another chaos-based pRNG proposed in [9] which uses two adaptive Chirikov maps and a comparison procedure to generate random bits. The following subsection presents the results of three experiments done in order to qualify the generator. First, a visual evaluation for the \((a,b)\) pairs generated by each entropy builder algorithm was made by plotting the pairs in a 2D space. The expectation is to see better randomness from plots that cover the entire plane as opposed to those showing distinctive patterns. The second experiment chose certain tuples of parameters and initial states that are known to produce periodic trajectories of the considered map.