use itertools::Itertools;

#[cfg(feature = "passphrase-gen")]
pub mod passphrase_gen;

#[cfg(feature = "password-gen")]
pub mod password_gen;

pub mod randomart;

#[cfg(feature = "ed25519")]
pub mod key_gen;

fn entropy(pass: &str) -> f32 {
    let mut r = 0;
    if pass.chars().any(|c| c.is_ascii_lowercase()) {
        r += 26;
    }
    if pass.chars().any(|c| c.is_ascii_uppercase()) {
        r += 26;
    }
    if pass.chars().any(|c| c.is_ascii_punctuation()) {
        r += 36;
    }
    if pass.chars().any(|c| c.is_ascii_digit()) {
        r += 10;
    }
    let len = pass.chars().count();
    let other = pass
        .chars()
        .filter(|c| {
            !(c.is_ascii_lowercase()
                || c.is_ascii_uppercase()
                || c.is_ascii_digit()
                || c.is_ascii_punctuation())
        })
        .dedup()
        .count();

    ((r + other) as f32).log2() * len as f32
}

#[cfg(test)]
mod tests {
    use crate::entropy;

    #[test]
    fn test_entropy() {
        println!(
            "{}",
            entropy("this is a long passphrase with quite a few words!")
        );
        println!(
            "{}",
            entropy("This Is A Long Passphrase With Quite A Few Words!")
        );
    }
}
