1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
extern crate rand;

use rand::seq::SliceRandom;
use std::fmt;

include!(concat!(env!("OUT_DIR"), "/diceware.rs"));

#[derive(Debug, Clone, Eq, PartialEq, Copy)]
pub struct BealeWord(&'static str);

#[derive(Debug, Clone, Eq, PartialEq, Copy)]
pub struct ReinholdWord(&'static str);

#[derive(Debug, Clone, Eq, PartialEq, Copy)]
pub struct MiniLockWord(&'static str);

impl BealeWord {
    pub fn new(word: &'static str) -> BealeWord {
        BealeWord(word)
    }

    pub fn entropy() -> f64 {
        (BEALE_WORDLIST.len() as f64).log2()
    }

    pub fn entropyn(n: u64) -> f64 {
        BealeWord::entropy() * (n as f64)
    }
}

impl ReinholdWord {
    pub fn new(word: &'static str) -> ReinholdWord {
        ReinholdWord(word)
    }

    pub fn entropy() -> f64 {
        (REINHOLD_WORDLIST.len() as f64).log2()
    }

    pub fn entropyn(n: u64) -> f64 {
        ReinholdWord::entropy() * (n as f64)
    }
}

impl MiniLockWord {
    pub fn new(word: &'static str) -> MiniLockWord {
        MiniLockWord(word)
    }

    pub fn entropy() -> f64 {
        (MINILOCK_WORDLIST.len() as f64).log2()
    }

    pub fn entropyn(n: u64) -> f64 {
        MiniLockWord::entropy() * (n as f64)
    }
}

impl rand::distributions::Distribution<BealeWord> for rand::distributions::Standard {
    fn sample<R: rand::Rng + ?Sized>(&self, mut rng: &mut R) -> BealeWord {
        *BEALE_WORDLIST.choose(&mut rng).unwrap()
    }
}

/*
impl rand::Rand for BealeWord {
    fn rand<R: rand::Rng>(rng: &mut R) -> BealeWord {
        rng.choose(&BEALE_WORDLIST).unwrap().clone()
    }
}
*/

impl fmt::Display for BealeWord {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let BealeWord(w) = self;
        write!(f, "{}", w)
    }
}

impl rand::distributions::Distribution<ReinholdWord> for rand::distributions::Standard {
    fn sample<R: rand::Rng + ?Sized>(&self, mut rng: &mut R) -> ReinholdWord {
        *REINHOLD_WORDLIST.choose(&mut rng).unwrap()
    }
}

/*
impl rand::Rand for ReinholdWord {
    fn rand<R: rand::Rng>(rng: &mut R) -> ReinholdWord {
        rng.choose(&REINHOLD_WORDLIST).unwrap().clone()
    }
}
*/

impl fmt::Display for ReinholdWord {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let ReinholdWord(w) = self;
        write!(f, "{}", w)
    }
}

impl rand::distributions::Distribution<MiniLockWord> for rand::distributions::Standard {
    fn sample<R: rand::Rng + ?Sized>(&self, mut rng: &mut R) -> MiniLockWord {
        *MINILOCK_WORDLIST.choose(&mut rng).unwrap()
    }
}

/*
impl rand::Rand for MiniLockWord {
    fn rand<R: rand::Rng>(rng: &mut R) -> MiniLockWord {
        rng.choose(&MINILOCK_WORDLIST).unwrap().clone()
    }
}
*/

impl fmt::Display for MiniLockWord {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let MiniLockWord(w) = self;
        write!(f, "{}", w)
    }
}