keyfork-mnemonic-generate: add failing test to track birthday paradox
This commit is contained in:
parent
6f00eb6fd7
commit
2c06b96953
|
@ -94,7 +94,7 @@ fn ensure_offline() {
|
||||||
// TODO: Can a Mnemonic be formatted using a wordlist, without allocating or without storing the
|
// TODO: Can a Mnemonic be formatted using a wordlist, without allocating or without storing the
|
||||||
// entire word list?
|
// entire word list?
|
||||||
struct Mnemonic {
|
struct Mnemonic {
|
||||||
words: Vec<usize>,
|
pub words: Vec<usize>,
|
||||||
wordlist: Vec<String>,
|
wordlist: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,4 +232,20 @@ mod tests {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn count_to_get_duplicate_words() {
|
||||||
|
let mut count = 0.;
|
||||||
|
let mut random_handle = File::open("/dev/urandom").unwrap();
|
||||||
|
let entropy = &mut [0u8; 256 / 8];
|
||||||
|
for _ in 0..100_000 {
|
||||||
|
random_handle.read_exact(&mut entropy[..]).unwrap();
|
||||||
|
let mut mnemonic = Mnemonic::from_entropy(&entropy[..256 / 8]).unwrap();
|
||||||
|
mnemonic.words.dedup();
|
||||||
|
if mnemonic.words.len() != 24 {
|
||||||
|
count += 1.;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("counts: {count} {}", count / 100_000.)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue