entropy_test 0.0.1

CLI tool and API to generate passphrases
Documentation
extern crate rand;
use rand::prelude::*;


// Function to determine passphrase difficulty: 
// easy, medium, hard, random, errror
pub fn difficulty(mode: &str) -> i32 {
    if mode == "easy" {
        thread_rng().gen_range(1, 3)
    } else if mode == "medium" {
        thread_rng().gen_range(3, 6)
    } else if mode == "hard" {
        thread_rng().gen_range(6, 9)
    } else if mode == "random" {
        thread_rng().gen_range(1, 9)
    } else {
        println!("Not a valid mode. Please set mode to easy, medium, or hard");
        0
    }
}

// Function to join all padding types into one vector
pub fn join_padding_types<'a>(numbers: Vec<&'a str>,
                              letters: Vec<&'a str>,
                              symbols: Vec<&'a str>,
                              other: Vec<&'a str>) -> Vec<&'a str> {
    
    let mut v: Vec<&str> = Vec::new();
    
    v.append(&mut numbers.clone());
    v.append(&mut letters.clone());
    v.append(&mut symbols.clone());
    v.append(&mut other.clone());
    
    v
    
}

// Function to create a padding string from the padding vector
pub fn padding(stuff: Vec<&str>,
               len: i32) -> Vec<&str> {
    
    let mut v: Vec<&str> = Vec::new();
    let l = thread_rng().gen_range(1, len);
    let s = thread_rng().gen_range(1, stuff.len());
    
    for _i in 0..l {
        v.push(stuff[s]);
    }
        
    v
    
}

// Function to generate a passphrase with padding
pub fn passphrase(words: Vec<&str>,
                  padding_chars: Vec<&str>,
                  mode: &str) -> String {
    
    // init variables
    let mut v: Vec<&str> = Vec::new();
    let d = difficulty(mode);
    let p = padding(padding_chars, d);
    
    // add words and padding to vector
    for _i in 0..d {
        let w = thread_rng().gen_range(1, words.len());
        v.push(words[w]);
        v.append(&mut p.clone());
    }

    // convert vector to string
    let mut passphrase = String::new();
    for _i in v {
        passphrase.push_str(_i);
    }

    // return passphrase string
    passphrase
    
}

// Function to create a random password to compare with 
// a random passphrase
pub fn password(stuff: Vec<&str>,
                len: i32) -> String {
        
    // init variables
    let mut v: Vec<&str> = Vec::new();
    
    // add random values to a vector
    for _i in 0..len {
        let s = thread_rng().gen_range(1, stuff.len());
        v.push(stuff[s])
    }
        
    // convert vector to string
    let mut password = String::new();
    for _i in v {
        password.push_str(_i);
    }
    
    // return password string
    password
}

// Create Alphabets
// - https://users.rust-lang.org/t/storing-strings-in-a-crate-library/23130/13

/* original try
pub static WORDS: &'static [&'static str] = &["apple", "bagel", "cat", "dolphin", "elephant", "frog", "gopher", "horse", "iguana", "jackrabbit", "kangaroo", "lizzard", "monkey", "nightengale", "otter", "prayingmantis", "quail", "rooster", "snake", "turtle", "ummm", "velocorapter", "walrus", "x", "yarr", "zebra"];
pub static NUMS: &'static [&'static str] = &["0","1","2","3","4","5","6","7","8","9"];
pub static SYMBOLS: &'static [&'static str] = &["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "{", "]", "}", "?", ".", ">", ",", "<", ";", "|", ":", "/"]; 
pub static LETTERS: &'static [&'static str] = &["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
pub static OTHER: &'static [&'static str] = &[""];
*/

/* as fixed arrays
pub static WORDS: [&'static str; 26] = ["apple", "bagel", "cat", "dolphin", "elephant", "frog", "gopher", "horse", "iguana", "jackrabbit", "kangaroo", "lizzard", "monkey", "nightengale", "otter", "prayingmantis", "quail", "rooster", "snake", "turtle", "ummm", "velocorapter", "walrus", "x", "yarr", "zebra"];
pub static NUMS: [&'static str; 10] = ["0","1","2","3","4","5","6","7","8","9"];
pub static SYMBOLS: [&'static str; 29] = ["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "{", "]", "}", "?", ".", ">", ",", "<", ";", "|", ":", "/"]; 
pub static LETTERS: [&'static str; 26] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
pub static OTHER: [&'static str; 1] = [""];
*/

// this works with `cargo run`
pub static WORDS: [&str; 26] = ["apple", "bagel", "cat", "dolphin", "elephant", "frog", "gopher", "horse", "iguana", "jackrabbit", "kangaroo", "lizzard", "monkey", "nightengale", "otter", "prayingmantis", "quail", "rooster", "snake", "turtle", "ummm", "velocorapter", "walrus", "x", "yarr", "zebra"];
pub static NUMS: [&str; 10] = ["0","1","2","3","4","5","6","7","8","9"];
pub static SYMBOLS: [&str; 29] = ["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "{", "]", "}", "?", ".", ">", ",", "<", ";", "|", ":", "/"]; 
pub static LETTERS: [&str; 26] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
pub static OTHER: [&str; 1] = [""];