gnu.crypto.tool
Class Ent
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.
- 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.
Ent
public Ent(String name,
SecureRandom prng)
getChiSquare
public double getChiSquare()
getChiSquareProbability
public double getChiSquareProbability()
getDuration
public long getDuration()
getMean
public double getMean()
getMeanPercentDeviation
public double getMeanPercentDeviation()
getPi
public double getPi()
getPiPercentDeviation
public double getPiPercentDeviation()
getSerialCorrelationCoefficient
public double getSerialCorrelationCoefficient()
getSetBits
public long getSetBits()
getTotalBits
public long getTotalBits()
main
public static void main(String[] args)
Copyright © 2001, 2002, 2003
Free Software Foundation,
Inc. All Rights Reserved.