I DONT UNDERSTAND TYPES

This commit is contained in:
Eryn Wells 2018-03-26 13:07:23 -04:00
parent 74589508b2
commit 9c6c5c8ac6
2 changed files with 28 additions and 0 deletions

View file

@ -93,6 +93,12 @@ impl HexDigest for Vec<u8> {
}
}
impl<'a> HexDigest for &'a [u8] {
fn hex_digest(self) -> String {
self.into_iter().map(|x| char::from_digit(*x as u32, 16).unwrap()).collect()
}
}
/*
* AsHexbytes --
*/

View file

@ -14,6 +14,8 @@ pub fn fixed(a: &str, b: &str) -> Result<String, FixedXORError> {
#[cfg(test)]
mod tests {
use hex::AsHexBytes;
use std::char;
use super::fixed;
#[test]
@ -24,4 +26,24 @@ mod tests {
let output = fixed(a, b);
assert_eq!(output.unwrap(), ex_output);
}
static ENGLISH_LETTER_FREQ: &'static str = "EARIOTNSLCUDPMHGBFYWKVXZJQ";
fn letter_freq_score(input: &str) -> f32 {
let mut score: f32 = 0.0;
score
}
#[test]
fn cryptopals13() {
let input = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
for key in 32u32..127 {
let possible_output = input.hex_bytes().valid()
.map(|c| char::from_u32(c as u32 ^ key))
.take_while(|c| c.is_some())
.map(|c| c.unwrap())
.collect::<String>();
println!("{}: {}", key, possible_output);
}
}
}