Starting on s1c4

This commit is contained in:
Eryn Wells 2018-04-08 08:51:06 -07:00
parent 350dc555de
commit c5f8321c84

View file

@ -4,11 +4,14 @@
extern crate cryptopals;
use std::f32;
use std::fs::File;
use std::io::{BufRead, BufReader};
use cryptopals::b64::Base64Encodable;
use cryptopals::hex::{HexDecodable, HexEncodable};
use cryptopals::letter_frequency::LetterFreq;
use cryptopals::xor::{FixedXOR, ByteXOR};
/// Base 64 encode some bytes.
#[test]
fn s1c1() {
let input = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d";
@ -17,6 +20,7 @@ fn s1c1() {
assert_eq!(output, ex_output);
}
/// XOR two arrays of bytes together to get a new byte string.
#[test]
fn s1c2() {
let a = "1c0111001f010100061a024b53535009181c";
@ -28,6 +32,7 @@ fn s1c2() {
assert_eq!(output, ex_output);
}
/// Determine the key for a single byte XOR encryption scheme using English letter frequency analysis.
#[test]
fn s1c3() {
let input = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
@ -51,3 +56,18 @@ fn s1c3() {
println!("{}: {:?} -> {}", best_key, best_output, best_score);
assert!(best_output.to_lowercase().contains("bacon"));
}
/// Detect a single byte XOR encryption scheme using the letter frequency analysis from s1c3.
#[test]
fn s1c4() {
let f = match File::open("resources/s1c4.txt") {
Ok(f) => f,
Err(e) => panic!("failed to open the strings file: {}", e),
};
let reader = BufReader::new(&f);
for line in reader.lines() {
let line = line.unwrap();
println!("{:?}", line);
let bytes = line.chars().hex_decoded();
}
}