Ent (GNU cryptographic primitives and tools)
Keywords: gnu.crypto.tool.Ent,Ent class

Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
| For the latest news and information visit The GNU Crypto project
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## gnu.crypto.tool
Class Ent

    java.lang.Object
      |
      +--gnu.crypto.tool.Ent

public class Ent
extends java.lang.Object

This is a Java implementation of Ent (A Pseudorandom Number Sequence Test Program) developed by John Walker) which applies various tests to sequences of bytes generated by the GNU Crypto library pseudo-random number generator implementations.

It is useful for those evaluating pseudorandom number generators for encryption and statistical sampling applications, compression algorithms, and other applications where the various computed indices are of interest.

For a designated PRNG algorithm, this class computes the following indices:

- Chi-square test: The chi-square test is the most commonly used test for the randomness of data, and is extremely sensitive to errors in pseudorandom sequence generators. The chi-square distribution is calculated for the stream of bytes in the file and expressed as an absolute number and a percentage which indicates how frequently a truly random sequence would exceed the value calculated. We interpret the percentage as the degree to which the sequence tested is suspected of being non-random. If the percentage is greater than 99% or less than 1%, the sequence is almost certainly not random. If the percentage is between 99% and 95% or between 1% and 5%, the sequence is suspect. Percentages between 90% and 95% and 5% and 10% indicate the sequence is almost suspect. Note that our JPEG file, while very dense in information, is far from random as revealed by the chi-square test.

Applying this test to the output of various pseudorandom sequence generators is interesting. The low-order 8 bits returned by the standard Unix rand() function, for example, yields:

Chi square distribution for 500000 samples is 0.01, and randomly would exceed this value 99.99 percent of the times.

While an improved generator [Park & Miller] reports:

Chi square distribution for 500000 samples is 212.53, and randomly would exceed this value 95.00 percent of the times.

Thus, the standard Unix generator (or at least the low-order bytes it returns) is unacceptably non-random, while the improved generator is much better but still sufficiently non-random to cause concern for demanding applications. Contrast both of these software generators with the chi-square result of a genuine random sequence created by timing radioactive decay events.

Chi square distribution for 32768 samples is 237.05, and randomly would exceed this value 75.00 percent of the times.

See [Knuth, pp. 35-40] for more information on the chi-square test.

- Arithmetic mean: This is simply the result of summing up all the (set) bits in the file and dividing by the file length. If the data are close to random, this should be about 0.5. If the mean departs from this value, the values are consistently high or low.
- Monte Carlo value for Pi: Each successive sequence of six bytes is used as 24 bit X and Y co-ordinates within a square. If the distance of the randomly-generated point is less than the radius of a circle inscribed within the square, the six-byte sequence is considered a "hit". The percentage of hits can be used to calculate the value of Pi. For very large streams (this approximation converges very slowly), the value will approach the correct value of Pi if the sequence is close to random. A 32768 byte file created by radioactive decay yielded: Monte Carlo value for Pi is 3.139648438 (error 0.06 percent).
- Serial correlation coefficient: This quantity measures the extent to which each byte in the file depends upon the previous byte. For random sequences, this value (which can be positive or negative) will, of course, be close to `zero`. A non-random byte stream such as a C program will yield a serial correlation coefficient on the order of `0.5`. Wildly predictable data such as uncompressed bitmaps will exhibit serial correlation coefficients approaching `1`. See [Knuth, pp. 64-65] for more details.

Constructor Summary
`Ent(IRandom prng)`
`Ent(java.lang.String name, java.security.SecureRandom prng)`

Method Summary
`void` | `computeIndices()`
`double` | `getChiSquare()`
`double` | `getChiSquareProbability()`
`long` | `getDuration()`
`double` | `getMean()`
`double` | `getMeanPercentDeviation()`
`double` | `getPi()`
`double` | `getPiPercentDeviation()`
`double` | `getSerialCorrelationCoefficient()`
`long` | `getSetBits()`
`long` | `getTotalBits()`
`static void` | `main(java.lang.String[] args)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Ent

    public Ent(IRandom prng)

### Ent

    public Ent(java.lang.String name,
               java.security.SecureRandom prng)

Method Detail

### main

    public static void main(java.lang.String[] args)

### computeIndices

    public void computeIndices()
                        throws LimitReachedException

    `LimitReachedException`

### getDuration

    public long getDuration()

### getTotalBits

    public long getTotalBits()

### getSetBits

    public long getSetBits()

### getMean

    public double getMean()

### getMeanPercentDeviation

    public double getMeanPercentDeviation()

### getChiSquare

    public double getChiSquare()

### getChiSquareProbability

    public double getChiSquareProbability()

### getSerialCorrelationCoefficient

    public double getSerialCorrelationCoefficient()

### getPi

    public double getPi()

### getPiPercentDeviation

    public double getPiPercentDeviation()

Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
| For the latest news and information visit The GNU Crypto project
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001, 2002, 2003, 2004 Free Software Foundation, Inc.