Skip to content

Commit

Permalink
Merge pull request #25 from triarius/chi-square
Browse files Browse the repository at this point in the history
  • Loading branch information
triarius authored Jul 23, 2023
2 parents 7e313f0 + af65890 commit 4dfabbe
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 29 deletions.
193 changes: 192 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ eyre = "0.6.8"
lazy_static = "1.4.0"
rand = "0.8.5"
regex = "1.9.1"

[dev-dependencies]
statrs = "0.16.0"
30 changes: 2 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod passphrase;
mod words;

use clap::Parser;
use eyre::Result;
use rand::{rngs::ThreadRng, Rng};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -24,34 +24,8 @@ fn main() -> Result<()> {

println!(
"{}",
passphrase(&mut rng, &mut words, args.num_words, &args.separator)
passphrase::new(&mut rng, &mut words, args.num_words, &args.separator)
);

Ok(())
}

fn passphrase(
rng: &mut ThreadRng,
words: &mut Vec<String>,
num_words: usize,
separator: &str,
) -> String {
if words.len() < num_words {
eprintln!(
"Your dictionary only has {} suitable words, but you asked for {} words.",
words.len(),
num_words
);
return "".to_string();
}

(0..num_words).for_each(|i| {
let j = rng.gen_range(0..words.len());
words.swap(i, j)
});

(0..num_words)
.map(|i| words[i].to_owned())
.collect::<Vec<String>>()
.join(separator)
}
Loading

0 comments on commit 4dfabbe

Please sign in to comment.