Thread: 2D Randomness Visualisation with Python, matplotlib and numpy

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2011
Posts
144
Rep Power
60

2D Randomness Visualisation with Python, matplotlib and numpy

A very basic Python script for 2D visualising randomness of given files
is available here

Index of /crypto/cryptanalysis/Random-Visualisation

Additionally inside the 2D-Example-Binary-Files folder you may find
resulting images of tests from several different PRNG/cipher algorithms
as well as the binary keystream files processed by the script.

It is a very simple test of which I assume that it should not show any
pattern in the keystream output of a cryptographically secure random
number generator.

Generation of the binary test file is just either piping the keystream
of the cipher into the desired test file or encrypting a prepared file
which consist of only 0x00 and pass the file's location - pure binary
keystream or encrypted file - as parameter to the script.

Nothing fancy so far but might still be helpful somehow.

Cheers,
Karl-Uwe

Below the test results on two binary files generated using two very
unreliable PRNG algorithms as well as the corresponding 2D image.

Binary Keystream File:
http://www.freecx.co.uk/crypto/crypt...in.crystalline

Resulting 2D-Image File
http://www.freecx.co.uk/crypto/crypt...rystalline.png

Code:
```======== Running Rabbit Test =========

========= Summary results of Rabbit =========

Version:          TestU01 1.2.3
File:             zero_4MB.bin.crystalline
Number of bits:   4194304
Number of statistics:  38
Total CPU time:   00:00:04.91
The following tests gave p-values outside [0.001, 0.9990]:
(eps  means a value < 1.0e-300):
(eps1 means a value < 1.0e-15):

Test                          p-value
----------------------------------------------
1  MultinomialBitsOver              eps
2  ClosePairsBitMatch, t = 2      4.6e-69
3  ClosePairsBitMatch, t = 4     2.5e-147
4  AppearanceSpacings              6.2e-4
6  LempelZiv                      1 - eps1
7  Fourier1                       1 - eps1
8  Fourier3                      5.6e-148
10  PeriodsInStrings                 eps
11  HammingWeight                    eps
12  HammingCorr, L = 32             1.1e-4
14  HammingCorr, L = 128           1 -  4.4e-5
15  HammingIndep, L = 16             eps
16  HammingIndep, L = 32             eps
17  HammingIndep, L = 64             eps
18  AutoCor                        1 -  3.2e-6
19  AutoCor                        1 - 5.8e-13
20  Run of bits                      eps
20  Run of bits                     9.1e-4
21  MatrixRank, 32 x 32             7.6e-4
24  RandomWalk1 H                    eps
24  RandomWalk1 M                    eps
24  RandomWalk1 J                    eps
24  RandomWalk1 R                    eps
24  RandomWalk1 C                    eps
25  RandomWalk1 H (L = 1024)         eps
25  RandomWalk1 M (L = 1024)         eps
25  RandomWalk1 J (L = 1024)         eps
25  RandomWalk1 R (L = 1024)         eps
25  RandomWalk1 C (L = 1024)         eps
26  RandomWalk1 H (L = 10016)        eps
26  RandomWalk1 M (L = 10016)        eps
26  RandomWalk1 J (L = 10016)      6.9e-10
----------------------------------------------
All other tests were passed

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

======== Running Alphabit Test ========

========= Summary results of Alphabit =========

Version:          TestU01 1.2.3
File:             zero_4MB.bin.crystalline
Number of bits:   4194304
Number of statistics:  17
Total CPU time:   00:00:00.32
The following tests gave p-values outside [0.001, 0.9990]:
(eps  means a value < 1.0e-300):
(eps1 means a value < 1.0e-15):

Test                          p-value
----------------------------------------------
1  MultinomialBitsOver, L = 2       eps
2  MultinomialBitsOver, L = 4       eps
3  MultinomialBitsOver, L = 8       eps
4  MultinomialBitsOver, L = 16      eps
5  HammingIndep, L = 16             eps
6  HammingIndep, L = 32             eps
7  HammingCorr, L = 32             1.1e-4
8  RandomWalk1 H (L = 64)           eps
8  RandomWalk1 M (L = 64)           eps
8  RandomWalk1 J (L = 64)           eps
8  RandomWalk1 R (L = 64)           eps
8  RandomWalk1 C (L = 64)           eps
9  RandomWalk1 H (L = 320)          eps
9  RandomWalk1 M (L = 320)          eps
9  RandomWalk1 J (L = 320)        1.1e-16
9  RandomWalk1 R (L = 320)         4.3e-4
----------------------------------------------
All other tests were passed```

Binary Keystream File:

Resulting 2D-Image File
http://www.freecx.co.uk/crypto/crypt...NG_4MB.bin.png

Code:
```======== Running Rabbit Test =========

========= Summary results of Rabbit =========

Version:          TestU01 1.2.3
Number of bits:   4194304
Number of statistics:  38
Total CPU time:   00:00:05.59
The following tests gave p-values outside [0.001, 0.9990]:
(eps  means a value < 1.0e-300):
(eps1 means a value < 1.0e-15):

Test                          p-value
----------------------------------------------
1  MultinomialBitsOver           4.5e-100
2  ClosePairsBitMatch, t = 2       4.9e-4
3  ClosePairsBitMatch, t = 4      1.1e-13
4  AppearanceSpacings               eps
7  Fourier1                         eps
8  Fourier3                         eps
12  HammingCorr, L = 32              eps
13  HammingCorr, L = 64              eps
14  HammingCorr, L = 128             eps
16  HammingIndep, L = 32             eps
17  HammingIndep, L = 64             eps
24  RandomWalk1 H                    eps
24  RandomWalk1 M                    eps
24  RandomWalk1 J                    eps
24  RandomWalk1 R                    eps
24  RandomWalk1 C                    eps
25  RandomWalk1 H (L = 1024)         eps
25  RandomWalk1 M (L = 1024)         eps
25  RandomWalk1 J (L = 1024)         eps
25  RandomWalk1 R (L = 1024)         eps
25  RandomWalk1 C (L = 1024)         eps
26  RandomWalk1 H (L = 10016)       4.5e-6
26  RandomWalk1 M (L = 10016)       1.9e-4
----------------------------------------------
All other tests were passed

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

======== Running Alphabit Test ========

========= Summary results of Alphabit =========

Version:          TestU01 1.2.3
Number of bits:   4194304
Number of statistics:  17
Total CPU time:   00:00:00.33
The following tests gave p-values outside [0.001, 0.9990]:
(eps  means a value < 1.0e-300):
(eps1 means a value < 1.0e-15):

Test                          p-value
----------------------------------------------
4  MultinomialBitsOver, L = 16    1 - 2.8e-11
6  HammingIndep, L = 32             eps
7  HammingCorr, L = 32              eps
8  RandomWalk1 H (L = 64)           eps
8  RandomWalk1 M (L = 64)           eps
8  RandomWalk1 J (L = 64)           eps
8  RandomWalk1 R (L = 64)           eps
8  RandomWalk1 C (L = 64)           eps
9  RandomWalk1 H (L = 320)          eps
9  RandomWalk1 M (L = 320)          eps
9  RandomWalk1 J (L = 320)          eps
9  RandomWalk1 R (L = 320)          eps
9  RandomWalk1 C (L = 320)          eps
----------------------------------------------
All other tests were passed```

Edit: the inevitable typo :-)
Last edited by Karl-Uwe Frank; February 20th, 2017 at 05:24 AM. Reason: the inevitable typo :-)