Skip to main content

High-performance implementations of BiEntropy metrics proposed by Grenville J. Croll

Project description

BiEntropy Randomness Metrics for Python
=======================================

This Python package provides high-performance implementations of the functions
and examples presented in "BiEntropy - The Approximate Entropy of a Finite
Binary String" by Grenville J. Croll, presented at ANPA 34 in 2013.
https://arxiv.org/abs/1305.0954

According to the paper, BiEntropy is "a simple algorithm which computes the
approximate entropy of a finite binary string of arbitrary length" using "a
weighted average of the Shannon Entropies of the string and all but the last
binary derivative of the string." In other words, these metrics can be used to
help assess the disorder or randomness of binary or byte strings, particularly
those that are too short for other randomness tests.

This module includes both a Python C extension and a pure Python module
implementing the BiEn and TBiEn metrics from the paper, as well as a suite of
tests that verify their correctness. These implementations are available under
the submodules 'cbientropy' and 'pybientropy'.

Aliases of C versions of BiEn and TBiEn are included at the top level of this
module for convenience.


Performance
-----------

According to the paper, the "BiEntropy algorithm evaluates the order and
disorder of a binary string of length n in O(n^2) time using O(n) memory." In
other words, the run time has quadratic growth and the memory requirement has
linear growth with respect to the string length.

The metrics are implemented in Python using the 'bitstring' package for
handling arbitrary length binary strings and in native C using the GNU Multiple
Precision (GMP) arithmetic library.

The following is a table of speed-ups from the Python to the C implementation
for various string byte lengths:

| Bytes | BiEn | TBiEn |
|-------|---------|---------|
| 16 | 229 | 155 |
| 32 | 217 | 149 |
| 48 | 212 | 150 |
| 64 | 221 | 161 |
| 128 | 267 | 196 |
| 256 | 340 | 257 |
| 512 | 502 | 370 |
| 1024 | 802 | 537 |

Following is a log-log plot of the average time to compute the various
implementations of BiEntropy on a 2.40GHz Intel(R) Xeon(R) E5645 CPU versus the
length of the input in bytes.

![Run Times](artwork/bientropy_times.png)


Requirements
------------

This package is tested with Python versions 2.7, 3.4, 3.5 and 3.6.

Installation:
* Python http://python.org/ (>= 2.7 or >= 3.4)
* bitstring http://pythonhosted.org/bitstring/
* NumPy http://numpy.org/

Compiling:
* GCC http://gcc.gnu.org/ on Linux
* MSVC 9 if using Python 2.7 on Windows
* https://www.microsoft.com/EN-US/DOWNLOAD/confirmation.aspx?id=44266
* MSVC 14 if using Python 3.x on Windows
* http://landinghub.visualstudio.com/visual-cpp-build-tools
* GMP http://gmplib.org/ or MPIR http://mpir.org/ on Windows

For running tests:
* mock https://pypi.org/project/mock/ if using Python 2.7


Install from pip
----------------

This package includes a C extension which has to be compiled for each platform.
Python wheels include compiled binary code and allow the extension to be
installed without requiring a compiler.

`pip >= 1.4` with `setuptools >= 0.8` will use a wheel if there is one available
for the target platform:
```
pip install --user BiEntropy
```

Once installed, the tests should be run with the command:
```
python -m bientropy.test_suite
```

A list of available wheel files is available at:
https://pypi.org/project/BiEntropy/#files


Install from Source
-------------------

The source code for the `bientropy` package can be cloned or downloaded from:
* GitHub: https://github.com/sandialabs/bientropy
* PyPI: https://pypi.org/project/BiEntropy

The [GMP library](http://gmplib.org/) and headers need to be installed before
compiling.

On Debian/Ubuntu:
```
apt-get install libgmp-dev
```

On RedHat:
```
yum install gmp-devel
```

Then, use `setup.py` to compile and install the package:
```
python setup.py install --user
```

Once installed, the tests should be run with the command:
```
python -m bientropy.test_suite
```


Compiling on Windows
--------------------

Compiling GMP on Microsoft Windows is only supported under Cygwin, MinGW or
DJGPP. However, this package can be compiled with MPIR, a fork of GMP, on
Windows. The source for MPIR is available at http://mpir.org/
The `setup.py` script expects the header files, library files and DLL to be
available under `mpir/dll/x64/Release`.

A compiled distribution of the MPIR libray was also available at:
http://www.holoborodko.com/pavel/mpfr/#download
Download the `MPFR-MPIR-x86-x64-MSVC2010.zip` file and extract `mpir` from the
ZIP file to this directory.

Once MPIR is ready, proceed as usual.
```
python setup.py install --user
```

After installing, the tests should be run with the command:
```
python -m bientropy.test_suite
```


Included Scripts
----------------

After installing, a demonstration can be run with this command:
```
python -m bientropy.demo
```
This file (`bientropy/demo.py`) also serves as a good example for using
the package.

The same benchmark script used to generate the data shown in the table and plot
above is also included. It can be run with:
```
python -m bientropy.benchmark
```


Development
-----------

To compile with debug symbols and with extra output, use:
```
python setup.py build_ext --force --debug --define DEBUG
```

To also disable compiler optimizations, use:
```
CFLAGS=-O0 python setup.py build_ext --force --debug --define DEBUG
```

To debug the extension with GDB:
```
$ gdb python
(gdb) run setup.py test
```

To run the Valgrind memcheck tool to check for memory corruption and leaks:
```
valgrind --xml=yes --xml-file=valgrind.xml ${python} setup.py test
```


Authors
-------

This package, consisting of the C implementations, Python implementations and
Python bindings were written by Ryan Helinski <rhelins@sandia.gov>.


License
-------
Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC
(NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
Government retains certain rights in this software.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

BiEntropy-1.0.4.tar.gz (26.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

BiEntropy-1.0.4-cp36-cp36m-win_amd64.whl (226.9 kB view details)

Uploaded CPython 3.6mWindows x86-64

BiEntropy-1.0.4-cp36-cp36m-manylinux1_x86_64.whl (167.7 kB view details)

Uploaded CPython 3.6m

BiEntropy-1.0.4-cp36-cp36m-manylinux1_i686.whl (159.2 kB view details)

Uploaded CPython 3.6m

BiEntropy-1.0.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (268.5 kB view details)

Uploaded CPython 3.6mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

BiEntropy-1.0.4-cp35-cp35m-win_amd64.whl (221.1 kB view details)

Uploaded CPython 3.5mWindows x86-64

BiEntropy-1.0.4-cp35-cp35m-manylinux1_x86_64.whl (167.7 kB view details)

Uploaded CPython 3.5m

BiEntropy-1.0.4-cp35-cp35m-manylinux1_i686.whl (159.2 kB view details)

Uploaded CPython 3.5m

BiEntropy-1.0.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (268.5 kB view details)

Uploaded CPython 3.5mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

BiEntropy-1.0.4-cp34-cp34m-manylinux1_x86_64.whl (167.5 kB view details)

Uploaded CPython 3.4m

BiEntropy-1.0.4-cp34-cp34m-manylinux1_i686.whl (159.0 kB view details)

Uploaded CPython 3.4m

BiEntropy-1.0.4-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (268.4 kB view details)

Uploaded CPython 3.4mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

BiEntropy-1.0.4-cp27-cp27mu-manylinux1_x86_64.whl (167.3 kB view details)

Uploaded CPython 2.7mu

BiEntropy-1.0.4-cp27-cp27mu-manylinux1_i686.whl (158.7 kB view details)

Uploaded CPython 2.7mu

BiEntropy-1.0.4-cp27-cp27m-win_amd64.whl (224.9 kB view details)

Uploaded CPython 2.7mWindows x86-64

BiEntropy-1.0.4-cp27-cp27m-manylinux1_x86_64.whl (167.3 kB view details)

Uploaded CPython 2.7m

BiEntropy-1.0.4-cp27-cp27m-manylinux1_i686.whl (158.7 kB view details)

Uploaded CPython 2.7m

BiEntropy-1.0.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (268.4 kB view details)

Uploaded CPython 2.7mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

File details

Details for the file BiEntropy-1.0.4.tar.gz.

File metadata

  • Download URL: BiEntropy-1.0.4.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for BiEntropy-1.0.4.tar.gz
Algorithm Hash digest
SHA256 a875aecfe39567105ea282eeb303d89fdfc464a424f09302079820d8a6926d59
MD5 0376682c875d864771aa9e2844eaa13f
BLAKE2b-256 c84b5304663ce499fb7618b1275d31b39438848c25cca80511c9b5c1032dec9e

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a6301cad6a930e152a21078e217d9ef8b6c9fb6dd477e309040775fd7b3c40ec
MD5 8f1a1ec81605117e6d516d9d68fda23a
BLAKE2b-256 bf33ad99b18859ce933acc4fe87300bbb8099e4a3cb27ccdfa42eee7f0ba0feb

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8163e3d2f8aae28cd686dffd1b3ad5d3f296bb6ba17e79ccd123d64b01b020ba
MD5 282caf85e37a53c8e8212236a9c17cd7
BLAKE2b-256 8543381047e020e7f595b3a84b77cc4c0fa10eec691d59b3f603a5bc26d36881

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 003372c20970d8f519f7d2aa636b8cdb44f3883e004aad969bee0f82e674f2f3
MD5 1de4ce601ce0cd8cafaabab05893872a
BLAKE2b-256 564d368c73e79b77bedf70635dc4d7953b12e55b4c28ea09ba38614b15f0cb1b

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 913364d85252589fac921f0d0de92b1b3da4738498bc7880f4148bf4df86f5ec
MD5 405fc2ce87a485fa769238a8e6af88bd
BLAKE2b-256 56bda43556d0b322eb54a0ae5c913287e76a39ce902fe4dcae5c2306551fc785

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 3f8d154dee76c62183de55b559296a0f2dfe5b3a262e43230f2fddade3c5aacd
MD5 313340cbb4a6eee418d289b6a5ec1901
BLAKE2b-256 f319305e6f71b24fe326347b9c36a9bf455f290f863b35faf1b3b55dee13aad4

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 350ebbaed19fea8d64b2760e98a93f51f53ac20f39783edb36eeccd8818f9a59
MD5 39782f5ab13dac818b95030e31094b7f
BLAKE2b-256 ed4833e9b1a837d1bdf43fdaec31f427e31a0501c68e88990fa7b755eae46548

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 153bce826e62213958f45f26a65f0472ea6df77f5c3f19135bc40cabe23157d4
MD5 be1e6f61eb6083590c5af095b9f27f59
BLAKE2b-256 94143ca2d2bacf66d16eef3fd04f6cf82ab7f0bb6cc4ba489abc98df0451645e

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 402a3fbcfd8727c0c05fa4c8875ae7d39703cc2932cf0cb0426d74a666e69999
MD5 afb56fba0bac4828397797b9b4225d6b
BLAKE2b-256 ffd3cca06f8a4830b08540ce7d69d7b647a9bba0fbc1b4d034ee17d69f833e7e

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6068839ccb551e451751d6a9aa1930069fbc90710c45f6d385486eabd777118b
MD5 cbb7106c459eb71a16344e2b2833a771
BLAKE2b-256 74d62b1dc17c032f1eb36698f15e24d106f3106ea354976b8a0ec0c50616b889

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 13b58690728bc7b7c03bc0f11eb5eba0c133bbc1ec78ea5f3ce9667898dd04cd
MD5 aa148df96825933f52570d90b8abbf17
BLAKE2b-256 67e2487de865f1a2456584db0d4f0bfd357bd07997fc040c9b9ade5b3e21ed98

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 65bebc24f1fd9d02391c59a8ce702eaab49f7bb1089a0f0c506aab760b8ef0bc
MD5 9b6c276fad5f566628d9e2e1d2cbd0d2
BLAKE2b-256 2021767fe39ffa854668118b8c9a2d83e9a2d3967b7a9703efa30ee5156a4ca4

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 53686e86f09560194c4bca55078f521639c264c91dacefab6609de24391af660
MD5 ece6dbaf514d54a47b5fc46ea4fa4395
BLAKE2b-256 93fe42f35ad3615c363f488075853f7ca58879659de97d0a0f061aace18c7a5a

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 7ae589813a87a93b0aed94532ebde020bb586cd4a4775a181735d0964aa0beac
MD5 10b3de610d614b338b7fda8ecf2333b2
BLAKE2b-256 52aa6b91ed716107c82f90fda979e7203d26941481dd66e0d5c34bbe45210711

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 fd55cfe5df4e899c6820031586bedfb92586ebfa1474521d88d9dba4a295fb4b
MD5 af4608124e22d3910ba76c2777e4a72d
BLAKE2b-256 020588f494185969e54d0a93914a8009623efd0ad366086f439a5ed532213fcb

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 08e707126209f175984d0297be6c64766685f5da18b9731a8d4acb95e90dca9d
MD5 0e050506b92837e73162e5c2203e9145
BLAKE2b-256 66e822475a5b9c1f543d0e79adbc549813f238db03664a3083637065eca12537

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 726541e0f16c717d9b71c6af49886293db30c6b16687f13e93840891ab77e6b5
MD5 4fcb9345f77495390ebfa2248877e2d1
BLAKE2b-256 b673742d75414aec3904d7fa213578f2d210260bc1a18d7fe6e175c56b3789bb

See more details on using hashes here.

File details

Details for the file BiEntropy-1.0.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for BiEntropy-1.0.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 a42235ac2ecfba2215fe8b6df2e6183b1bfc6ac5c5bd14d9a4803879732acc32
MD5 2556c9930bf57dd24c35a9a8372c42fc
BLAKE2b-256 329f605dc148a65c5e08d2d9d448801110e6b7fe5ee2f11e37f994fc88e31b03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page