INTRODUCTION
============

PENG4 ("Permutation Engine 4") is an implementation of an encryption algorithm 
based on long-distance bit permutations. It is still experimental. Written in C, 
it is suprisingly fast on modern computers. Lower performance is partially 
intended because of more difficult brute force attacks. The project was started 
in 1998, and in generation 4 the main objective was to avoid manual 
optimizations, since surprisingly, bitpacking and access ordering have made 
things worse. The algorithm and the tool is intended for top secret material, 
albeit its implementation is experimental and may be faulty or too simplistic in 
some point of view. Caveat utilitor!

The current algorithm can be described with CBC(X-P-X), that means, a plaintext
gets XORed, permutated and XORed again, with each round, and a CBC block cipher
mode of operation is applied.  Different sets (called "variations") are applied
in proper order.

Klaus-Juergen Wolf
yanestra !at! lab6 !dot! seismic !dot! de
2015-05-18


USAGE
=====

Most important, option -O:

    ./peng -O blocksize,rounds,variations

these are three numerics, the first one being the block size in which the bits
are permuted.  You may choose any number you want, but the program gets slower
the bigger the block size is.  The second is the number of rounds, this is the
number of how many times the X-P-X permutation/encryption process is repeated
on a single block (with different parameters, of course).  The third is the
number of variations, meaning the number of blocks on which another cycle of
permutation/encryption is applied, before the algorithm starts with the first
one again.

Within a block, the bits are permutated so that the very first bit may land on
the very last position.

You may want to use option -m if you have a CPU with more than one core (or
more than one CPU :-).


THIRD PARTY SOFTWARE
====================

Algorithms used:

MT19937
BSD License
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

Whirlpool Hash
Public Domain
https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip

Recommended tools:

ENT (Random)
Public Domain
http://www.fourmilab.ch/random/

http://www.phy.duke.edu/~rgb/General/dieharder.php


QUALITY
=======

Some entropy measurements with ent:

$ ent urandom_testfile 
Entropy = 7.999997 bits per byte.

Optimum compression would reduce the size
of this 67223520 byte file by 0 percent.

Chi square distribution for 67223520 samples is 237.88, and randomly
would exceed this value 77.22 percent of the times.

Arithmetic mean value of data bytes is 127.4953 (127.5 = random).
Monte Carlo value for Pi is 3.141918543 (error 0.01 percent).
Serial correlation coefficient is 0.000080 (totally uncorrelated = 0.0).


$ ent aes_testfile 
Entropy = 7.999997 bits per byte.

Optimum compression would reduce the size
of this 67109157 byte file by 0 percent.

Chi square distribution for 67109157 samples is 277.43, and randomly
would exceed this value 15.99 percent of the times.

Arithmetic mean value of data bytes is 127.4929 (127.5 = random).
Monte Carlo value for Pi is 3.142242562 (error 0.02 percent).
Serial correlation coefficient is 0.000083 (totally uncorrelated = 0.0).


$ ent testfile.enc
Entropy = 7.999995 bits per byte.

Optimum compression would reduce the size
of this 107544576 byte file by 0 percent.

Chi square distribution for 107544576 samples is 724.99, and randomly
would exceed this value less than 0.01 percent of the times.

Arithmetic mean value of data bytes is 127.5086 (127.5 = random).
Monte Carlo value for Pi is 3.140441560 (error 0.04 percent).
Serial correlation coefficient is -0.000022 (totally uncorrelated = 0.0).


$ ent ~/1mbtest-entropy.bin 
Entropy = 7.999816 bits per byte.

Optimum compression would reduce the size
of this 1048576 byte file by 0 percent.

Chi square distribution for 1048576 samples is 267.66, and randomly
would exceed this value 28.06 percent of the times.

Arithmetic mean value of data bytes is 127.5992 (127.5 = random).
Monte Carlo value for Pi is 3.138302377 (error 0.10 percent).
Serial correlation coefficient is 0.000267 (totally uncorrelated = 0.0).
