Struct Entropy

Source
pub struct Entropy {
    pub byte_count: [u64; 256],
    pub length: u64,
}
Expand description

Contains metadata about the file that’s being used in the Entropy calculation.

byte_count is a lookup table that contains the number of occurances of a byte specified by the index, e.g. 0x00 is byte_count[0].

length is the number of bytes in the file.

Fields§

§byte_count: [u64; 256]§length: u64

Implementations§

Source§

impl Entropy

Source

pub fn new(file: &File) -> Entropy

Gets metadata for the Entropy calculation from a File reference

Source

pub fn shannon_entropy(&self) -> f32

Measures the Shannon entropy based on the frequency table and returns it as a float.

The equation is defined as: H(X) = - \sum_{i=0}^{n} P(x_i) log_2 P(x_i) It can be described as the minimum number of bits (per symbol) to encode the input. Thus the output will be between 0 and 8. See https://en.wikipedia.org/wiki/Entropy_(information_theory) for more information.

Source

pub fn metric_entropy(&self) -> f32

Measures the metric entropy based on the Shannon entropy of the generated frequency table and returns it as a float between 0 and 1.

Metric entropy is derived by dividing the Shannon entropy by the length of the string being measured. It can be described as the uncertainty or randomness of a string, where 1 means information is uniformly distributed across the string.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.