The tropy commandline tool takes bytes or input from std in and calculates the Shannon entropy then it display them colour coded in the terminal.
With Rust installed run:
shell
cargo install tropy
```shell
tropy target/release/tropy --bytes 1024
```
will yield something like this:
```shell
cat /dev/urandom | tropy - --csv ``` #
Add this to your Cargo.toml
:
```toml
. tropy = { version = "0.1.0", default_features = false } .
And to use the entropy calculator in your program/library add this:
rust
use std::io::Write;
use tropy::Calculator;
let mut calc = Calculator::new();
// write some bytes calc.write(&[0u8]).unwrap(); calc.write(&[1u8]).unwrap();
// calculate the entropy over the accumulated state // and reset the calculator let e = calc.entropy(); assert_eq!(e,1.0);
```