Skip to content

Commit

Permalink
Fix tests and math
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhannah committed Aug 3, 2022
1 parent 2b7007f commit 28bce05
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pkpw"
version = "1.1.2"
version = "1.1.3"
authors = ["Jesse Brooklyn Hannah <jesse@jbhannah.net>"]
edition = "2021"
license = "MIT"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cargo install pkpw

```console
$ pkpw -h
pkpw 1.1.2
pkpw 1.1.3
Jesse Brooklyn Hannah <jesse@jbhannah.net>
What if correct horse battery staple, but Pokémon.

Expand Down Expand Up @@ -62,15 +62,15 @@ $$
where a brute-force attack will need an average of $2^{E-1}$ guesses to
crack a password with $E$ bits of entropy.

By default, `pkpw` chooses **4** Pokémon names from the pool of [**913** known
By default, `pkpw` chooses **4** Pokémon names from the pool of [**915** known
Pokémon][names], resulting in an entropy of

$$
E = log_2(913^4) \approx 39.338
E = log_2(915^4) \approx 39.35
$$

bits. A brute-force attack that knows to use the 913 known Pokémon names as
the pool of values would take $3.474 \times 10^{11}$ guesses on average to
bits. A brute-force attack that knows to use the 915 known Pokémon names as
the pool of values would take $3.505 \times 10^{11}$ guesses on average to
correctly guess a password, or a bit more than **11 years** at 1000 guesses
per second.

Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ mod test {
/// Ensure that generate() generates a password string.
#[test]
fn test_generate() {
let mut rng = rng_from_seed(913);
let mut rng = rng_from_seed(915);

assert_eq!(
"Shroomish Venusaur Froakie Tyranitar".to_string(),
"Smoliv Trapinch Swanna Aromatisse".to_string(),
generate(None, 4, " ", &mut rng)
);
}
Expand All @@ -80,10 +80,10 @@ mod test {
/// length.
#[test]
fn test_generate_length() {
let mut rng = rng_from_seed(913);
let mut rng = rng_from_seed(915);

assert_eq!(
"Shroomish Venusaur Froakie Tyranitar Wingull".to_string(),
"Smoliv Trapinch Swanna Aromatisse Charjabug".to_string(),
generate(Some(40), 4, " ", &mut rng)
);
}
Expand All @@ -92,10 +92,10 @@ mod test {
/// separator between words.
#[test]
fn test_generate_separator() {
let mut rng = rng_from_seed(913);
let mut rng = rng_from_seed(915);

assert_eq!(
"Shroomish-Venusaur-Froakie-Tyranitar".to_string(),
"Smoliv-Trapinch-Swanna-Aromatisse".to_string(),
generate(None, 4, "-", &mut rng)
);
}
Expand All @@ -104,10 +104,10 @@ mod test {
/// digit separators.
#[test]
fn test_generate_digit() {
let mut rng = rng_from_seed(913);
let mut rng = rng_from_seed(915);

assert_eq!(
"Shroomish7Venusaur0Froakie2Tyranitar".to_string(),
"Smoliv7Trapinch6Swanna5Aromatisse".to_string(),
generate(None, 4, "digit", &mut rng)
);
}
Expand All @@ -116,10 +116,10 @@ mod test {
/// special character separators.
#[test]
fn test_generate_special() {
let mut rng = rng_from_seed(913);
let mut rng = rng_from_seed(915);

assert_eq!(
"Shroomish#Venusaur`Froakie/Tyranitar".to_string(),
"Smoliv=Trapinch-Swanna/Aromatisse".to_string(),
generate(None, 4, "special", &mut rng)
);
}
Expand All @@ -128,11 +128,11 @@ mod test {
/// the slice of separators.
#[test]
fn test_join() {
let mut rng = rng_from_seed(913);
let picked = vec!["Shroomish", "Venusaur", "Froakie", "Tyranitar"];
let mut rng = rng_from_seed(915);
let picked = vec!["Smoliv", "Trapinch", "Swanna", "Aromatisse"];

assert_eq!(
"Shroomish7Venusaur0Froakie2Tyranitar",
"Smoliv7Trapinch6Swanna5Aromatisse",
join(picked, DIGITS, &mut rng)
);
}
Expand Down
24 changes: 12 additions & 12 deletions src/pokemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::array::IntoIter;
use lazy_static::lazy_static;
use rand::{prelude::SliceRandom, Rng};

pub const POKEMON_COUNT: usize = 913;
pub const POKEMON_COUNT: usize = 915;

lazy_static! {
/// Array of all Pokémon names, in English and ASCII-normalized (e.g.
Expand Down Expand Up @@ -70,7 +70,7 @@ mod test {
/// Pokémon names.
#[test]
fn test_new() {
let pokemon = from_seed(913);
let pokemon = from_seed(915);

assert_eq!(pokemon.inner.len(), POKEMON_COUNT);
assert_ne!(pokemon.inner, *POKEMON);
Expand All @@ -80,7 +80,7 @@ mod test {
/// arrays of names.
#[test]
fn test_new_new() {
let pokemon_1 = from_seed(913);
let pokemon_1 = from_seed(915);
let pokemon_2 = from_seed(319);

assert_ne!(pokemon_1.inner, pokemon_2.inner);
Expand All @@ -92,7 +92,7 @@ mod test {
/// names.
#[test]
fn test_into_inner() {
let pokemon = from_seed(913);
let pokemon = from_seed(915);
let inner = pokemon.into_inner();

assert_eq!(inner.len(), POKEMON_COUNT);
Expand All @@ -104,11 +104,11 @@ mod test {
/// length 1.
#[test]
fn test_length() {
let mut pokemon = from_seed(913);
let mut pokemon = from_seed(915);
let picked = pokemon.length(40, 1);

assert_eq!(
vec!["Shroomish", "Venusaur", "Froakie", "Tyranitar", "Wingull"],
vec!["Smoliv", "Trapinch", "Swanna", "Aromatisse", "Charjabug"],
picked
);
assert!(picked.join(" ").len() > 40);
Expand All @@ -117,10 +117,10 @@ mod test {
/// Ensure that pick(4) returns a vector of four strings.
#[test]
fn test_pick() {
let mut pokemon = from_seed(913);
let mut pokemon = from_seed(915);

assert_eq!(
vec!["Shroomish", "Venusaur", "Froakie", "Tyranitar"],
vec!["Smoliv", "Trapinch", "Swanna", "Aromatisse"],
pokemon.pick(4)
);
}
Expand All @@ -129,15 +129,15 @@ mod test {
/// names.
#[test]
fn test_pick_pick() {
let mut pokemon = from_seed(913);
let mut pokemon = from_seed(915);

assert_eq!(vec!["Shroomish", "Venusaur", "Froakie"], pokemon.pick(3));
assert_eq!(vec!["Tyranitar", "Wingull"], pokemon.pick(2));
assert_eq!(vec!["Smoliv", "Trapinch", "Swanna"], pokemon.pick(3));
assert_eq!(vec!["Aromatisse", "Charjabug"], pokemon.pick(2));
}

/// Ensure that all Pokémon names are loaded.
#[test]
fn test_pokemon() {
assert_eq!(POKEMON.len(), 913);
assert_eq!(POKEMON.len(), 915);
}
}

0 comments on commit 28bce05

Please sign in to comment.