Struct Bytestat

Source
pub struct Bytestat { /* private fields */ }

Implementations§

Source§

impl Bytestat

Source

pub fn new() -> Bytestat

Create new Bytestat object.

§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
Examples found in repository?
examples/bytestat.rs (line 16)
14fn main() {
15
16  let mut stats = Bytestat::new();
17  let mut counter:u128 = 0;
18  let percent = 256 * 4096;
19
20  for x in std::io::stdin().bytes() {
21    match x {
22        Ok(data) => {
23          stats.analyze(data);
24          counter += 1;
25        },
26        Err(err) => {
27          eprintln!("{:?}", err);
28        }
29    }
30  }
31
32  println!("\nRAW SCORES AS STRING");
33  println!("{}", stats.get_scores_string("\n"));
34
35  println!("\nFINAL SCORE");
36  println!("{} samples", counter );
37  println!("{}{:.0}%", if counter < (percent * 100) {"~"} else {""}, stats.get_score() );
38
39}
Source

pub fn analyze(&mut self, value: u8)

Analyze one byte, bytes must be analysed in sequence. If bytes are not analyzed in sequence, the final score will not be valid. Repeat as needed.

§Arguments
  • value - A byte to be analyzed, u8
§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
 
for x in 0..limit {
  let my_byte = get_random_byte();
  stats.analyze( my_byte );
}
Examples found in repository?
examples/bytestat.rs (line 23)
14fn main() {
15
16  let mut stats = Bytestat::new();
17  let mut counter:u128 = 0;
18  let percent = 256 * 4096;
19
20  for x in std::io::stdin().bytes() {
21    match x {
22        Ok(data) => {
23          stats.analyze(data);
24          counter += 1;
25        },
26        Err(err) => {
27          eprintln!("{:?}", err);
28        }
29    }
30  }
31
32  println!("\nRAW SCORES AS STRING");
33  println!("{}", stats.get_scores_string("\n"));
34
35  println!("\nFINAL SCORE");
36  println!("{} samples", counter );
37  println!("{}{:.0}%", if counter < (percent * 100) {"~"} else {""}, stats.get_score() );
38
39}
Source

pub fn get_score_non_zero(&mut self) -> f64

Generate the score based on distribution of unique bytes being present in the set.

(unique byte present in set) / (maximum number of possible unique bytes, 256)

§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
 
for x in 0..limit {
  let my_byte = get_random_byte();
  stats.analyze( my_byte );
}
 
stats.get_score_non_zero()
Source

pub fn get_score_unique(&mut self) -> f64

Generate the score based on the uniqueness of the bytes distribution in the set. The score is between 0.0 and 1.0. Any score lower than 0.99 should be considered problematic.

(unique byte count in set) / (maximum number of possible unique bytes, 256)

§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
 
for x in 0..limit {
  let my_byte = get_random_byte();
  stats.analyze( my_byte );
}
 
stats.get_score_unique()
Source

pub fn get_score_amplitude(&mut self) -> f64

Generate the score based on the amplitude of the bytes distribution in the set. The score is between 0.0 and 1.0. Any score lower than 0.99 should be considered problematic.

((bytes count max) - (bytes count min)) / (bytes count max)

§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
 
for x in 0..limit {
  let my_byte = get_random_byte();
  stats.analyze( my_byte );
}
 
stats.get_score_amplitude()
Source

pub fn get_score_interval_continuity(&mut self) -> f64

Generate the sub score based on the amplitude of the continuity of significant interval measurements. The score is between 0 and 1. Any score lower than 0.99 should be considered problematic.

( 1 … interval_largest [] ) / (interval_largest)

§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
 
for x in 0..limit {
  let my_byte = get_random_byte();
  stats.analyze( my_byte );
}
 
stats.get_score_amplitude()
Source

pub fn get_score_interval_amplitude(&mut self) -> f64

Generate the score based on the amplitude of significant interval measurements relative to twice the range of byte. The score is between 0.0 and 1.0. Any score lower than 1.0 should be considered problematic.

( interval_largest ) / 512

§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
 
for x in 0..limit {
  let my_byte = get_random_byte();
  stats.analyze( my_byte );
}
 
stats.get_score_interval_amplitude()
Source

pub fn get_score(&mut self) -> f64

Generate the final score based on the 5 individual tests. Score between 0 and 100. 99 or lower is very problematic.

§Examples
use bytestat::Bytestat;
let stats = Bytestat::new();
 
for x in 0..limit {
  let my_byte = get_random_byte();
  stats.analyze( my_byte );
}
 
stats.get_score()
Examples found in repository?
examples/bytestat.rs (line 37)
14fn main() {
15
16  let mut stats = Bytestat::new();
17  let mut counter:u128 = 0;
18  let percent = 256 * 4096;
19
20  for x in std::io::stdin().bytes() {
21    match x {
22        Ok(data) => {
23          stats.analyze(data);
24          counter += 1;
25        },
26        Err(err) => {
27          eprintln!("{:?}", err);
28        }
29    }
30  }
31
32  println!("\nRAW SCORES AS STRING");
33  println!("{}", stats.get_scores_string("\n"));
34
35  println!("\nFINAL SCORE");
36  println!("{} samples", counter );
37  println!("{}{:.0}%", if counter < (percent * 100) {"~"} else {""}, stats.get_score() );
38
39}
Source

pub fn get_scores_array(&mut self) -> [f64; 6]

Source

pub fn get_scores_string(&mut self, seperator: &str) -> String

Examples found in repository?
examples/bytestat.rs (line 33)
14fn main() {
15
16  let mut stats = Bytestat::new();
17  let mut counter:u128 = 0;
18  let percent = 256 * 4096;
19
20  for x in std::io::stdin().bytes() {
21    match x {
22        Ok(data) => {
23          stats.analyze(data);
24          counter += 1;
25        },
26        Err(err) => {
27          eprintln!("{:?}", err);
28        }
29    }
30  }
31
32  println!("\nRAW SCORES AS STRING");
33  println!("{}", stats.get_scores_string("\n"));
34
35  println!("\nFINAL SCORE");
36  println!("{} samples", counter );
37  println!("{}{:.0}%", if counter < (percent * 100) {"~"} else {""}, stats.get_score() );
38
39}

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.