summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-04-09 03:04:54 -0400
committerJesse Luehrs <doy@tozt.net>2019-04-09 03:20:43 -0400
commit4c12a9eed43b6c0a2c3b194a7201ba25e0b8432b (patch)
tree8c8c5c1f92b955e05171b66b3a8d125608feaabf /tests
parentf92b84f214923a180b455eb7f5dbb69f6973db87 (diff)
downloadmatasano-4c12a9eed43b6c0a2c3b194a7201ba25e0b8432b.tar.gz
matasano-4c12a9eed43b6c0a2c3b194a7201ba25e0b8432b.zip
stop using rustc_serialize
Diffstat (limited to 'tests')
-rw-r--r--tests/set1.rs63
-rw-r--r--tests/set2.rs31
-rw-r--r--tests/set3.rs14
-rw-r--r--tests/util.rs9
4 files changed, 59 insertions, 58 deletions
diff --git a/tests/set1.rs b/tests/set1.rs
index f1db7e5..f8d0981 100644
--- a/tests/set1.rs
+++ b/tests/set1.rs
@@ -1,14 +1,13 @@
-use rustc_serialize::hex::FromHex;
-
mod util;
#[test]
fn problem_1() {
- let hex = "49276d206b696c6c696e6720796f757220627261\
- 696e206c696b65206120706f69736f6e6f757320\
- 6d757368726f6f6d"
- .from_hex()
- .unwrap();
+ let hex = hex::decode(
+ "49276d206b696c6c696e6720796f757220627261\
+ 696e206c696b65206120706f69736f6e6f757320\
+ 6d757368726f6f6d",
+ )
+ .unwrap();
let base64 = "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEg\
cG9pc29ub3VzIG11c2hyb29t";
let got = matasano::to_base64(&hex[..]);
@@ -17,19 +16,21 @@ fn problem_1() {
#[test]
fn problem_2() {
- let bytes1 = "1c0111001f010100061a024b53535009181c".from_hex().unwrap();
- let bytes2 = "686974207468652062756c6c277320657965".from_hex().unwrap();
- let expected = "746865206b696420646f6e277420706c6179".from_hex().unwrap();
+ let bytes1 = hex::decode("1c0111001f010100061a024b53535009181c").unwrap();
+ let bytes2 = hex::decode("686974207468652062756c6c277320657965").unwrap();
+ let expected =
+ hex::decode("746865206b696420646f6e277420706c6179").unwrap();
let got = matasano::fixed_xor(&bytes1[..], &bytes2[..]);
assert_eq!(got, expected);
}
#[test]
fn problem_3() {
- let ciphertext = "1b37373331363f78151b7f2b783431333d783978\
- 28372d363c78373e783a393b3736"
- .from_hex()
- .unwrap();
+ let ciphertext = hex::decode(
+ "1b37373331363f78151b7f2b783431333d783978\
+ 28372d363c78373e783a393b3736",
+ )
+ .unwrap();
let plaintext = b"Cooking MC's like a pound of bacon";
let got = matasano::crack_single_byte_xor(&ciphertext[..]);
assert_eq!(got, &plaintext[..]);
@@ -48,12 +49,13 @@ fn problem_5() {
let plaintext = b"Burning 'em, if you ain't quick and nimble\n\
I go crazy when I hear a cymbal";
let key = b"ICE";
- let ciphertext = "0b3637272a2b2e63622c2e69692a23693a2a3c63\
- 24202d623d63343c2a26226324272765272a282b\
- 2f20430a652e2c652a3124333a653e2b2027630c\
- 692b20283165286326302e27282f"
- .from_hex()
- .unwrap();
+ let ciphertext = hex::decode(
+ "0b3637272a2b2e63622c2e69692a23693a2a3c63\
+ 24202d623d63343c2a26226324272765272a282b\
+ 2f20430a652e2c652a3124333a653e2b2027630c\
+ 692b20283165286326302e27282f",
+ )
+ .unwrap();
let got = matasano::repeating_key_xor(plaintext, key);
assert_eq!(got, ciphertext);
}
@@ -79,16 +81,17 @@ fn problem_7() {
#[test]
fn problem_8() {
let possibles = util::read_as_hex_lines("data/8.txt");
- let ciphertext = "d880619740a8a19b7840a8a31c810a3d08649af7\
- 0dc06f4fd5d2d69c744cd283e2dd052f6b641dbf\
- 9d11b0348542bb5708649af70dc06f4fd5d2d69c\
- 744cd2839475c9dfdbc1d46597949d9c7e82bf5a\
- 08649af70dc06f4fd5d2d69c744cd28397a93eab\
- 8d6aecd566489154789a6b0308649af70dc06f4f\
- d5d2d69c744cd283d403180c98c8f6db1f2a3f9c\
- 4040deb0ab51b29933f2c123c58386b06fba186a"
- .from_hex()
- .unwrap();
+ let ciphertext = hex::decode(
+ "d880619740a8a19b7840a8a31c810a3d08649af7\
+ 0dc06f4fd5d2d69c744cd283e2dd052f6b641dbf\
+ 9d11b0348542bb5708649af70dc06f4fd5d2d69c\
+ 744cd2839475c9dfdbc1d46597949d9c7e82bf5a\
+ 08649af70dc06f4fd5d2d69c744cd28397a93eab\
+ 8d6aecd566489154789a6b0308649af70dc06f4f\
+ d5d2d69c744cd283d403180c98c8f6db1f2a3f9c\
+ 4040deb0ab51b29933f2c123c58386b06fba186a",
+ )
+ .unwrap();
let got = matasano::find_aes_128_ecb_encrypted_string(&possibles[..]);
assert_eq!(got, ciphertext);
}
diff --git a/tests/set2.rs b/tests/set2.rs
index a8de407..04614de 100644
--- a/tests/set2.rs
+++ b/tests/set2.rs
@@ -2,7 +2,6 @@ use std::borrow::ToOwned;
use std::collections::HashMap;
use rand::Rng;
-use rustc_serialize::base64::FromBase64;
mod util;
@@ -74,13 +73,14 @@ fn problem_11() {
#[test]
fn problem_12() {
- let padding = b"Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWct\
- dG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpU\
- aGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq\
- dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5v\
- LCBJIGp1c3QgZHJvdmUgYnkK"
- .from_base64()
- .unwrap();
+ let padding = base64::decode(
+ &b"Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWct\
+ dG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpU\
+ aGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq\
+ dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5v\
+ LCBJIGp1c3QgZHJvdmUgYnkK"[..],
+ )
+ .unwrap();
let fixed_padding = |input: &[u8]| -> Vec<u8> {
return input.iter().chain(padding.iter()).map(|x| *x).collect();
};
@@ -137,13 +137,14 @@ fn problem_13() {
#[test]
fn problem_14() {
- let padding = b"Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWct\
- dG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpU\
- aGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq\
- dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5v\
- LCBJIGp1c3QgZHJvdmUgYnkK"
- .from_base64()
- .unwrap();
+ let padding = base64::decode(
+ &b"Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWct\
+ dG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpU\
+ aGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq\
+ dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5v\
+ LCBJIGp1c3QgZHJvdmUgYnkK"[..],
+ )
+ .unwrap();
let front_padding: Vec<u8> = rand::thread_rng()
.sample_iter(&rand::distributions::Standard)
.take(rand::thread_rng().gen_range(1, 100))
diff --git a/tests/set3.rs b/tests/set3.rs
index 5d66e88..830d714 100644
--- a/tests/set3.rs
+++ b/tests/set3.rs
@@ -1,5 +1,4 @@
use rand::{FromEntropy, Rng};
-use rustc_serialize::base64::FromBase64;
mod util;
@@ -22,7 +21,7 @@ fn problem_17() {
static mut CHOSEN_PLAINTEXT_IDX: usize = 0;
let encrypter = || {
let idx = rand::thread_rng().gen_range(0, strings.len());
- let plaintext = strings[idx].from_base64().unwrap();
+ let plaintext = base64::decode(strings[idx]).unwrap();
unsafe { CHOSEN_PLAINTEXT_IDX = idx };
let iv = util::random_aes_128_key();
return (
@@ -45,17 +44,18 @@ fn problem_17() {
&validator,
);
let idx = unsafe { CHOSEN_PLAINTEXT_IDX.clone() };
- let expected = strings[idx].from_base64().unwrap();
+ let expected = base64::decode(strings[idx]).unwrap();
assert_eq!(plaintext, expected);
}
}
#[test]
fn problem_18() {
- let ciphertext = b"L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syL\
- XzhPweyyMTJULu/6/kXX0KSvoOLSFQ=="
- .from_base64()
- .unwrap();
+ let ciphertext = base64::decode(
+ &b"L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syL\
+ XzhPweyyMTJULu/6/kXX0KSvoOLSFQ=="[..],
+ )
+ .unwrap();
let plaintext =
&b"Yo, VIP Let's kick it Ice, Ice, baby Ice, Ice, baby "[..];
let got = matasano::aes_128_ctr(&ciphertext[..], b"YELLOW SUBMARINE", 0);
diff --git a/tests/util.rs b/tests/util.rs
index a253c2d..0d1e37f 100644
--- a/tests/util.rs
+++ b/tests/util.rs
@@ -4,14 +4,11 @@ use rand::{Rng, RngCore};
use std::fs::File;
use std::io::prelude::*;
-use rustc_serialize::base64::FromBase64;
-use rustc_serialize::hex::FromHex;
-
pub fn read_as_hex_lines(filename: &str) -> Vec<Vec<u8>> {
let fh = File::open(filename).unwrap();
return std::io::BufReader::new(fh)
.lines()
- .map(|line| line.unwrap().from_hex().unwrap())
+ .map(|line| hex::decode(line.unwrap()).unwrap())
.collect();
}
@@ -19,7 +16,7 @@ pub fn read_as_base64_lines(filename: &str) -> Vec<Vec<u8>> {
let fh = File::open(filename).unwrap();
return std::io::BufReader::new(fh)
.lines()
- .map(|line| line.unwrap().from_base64().unwrap())
+ .map(|line| base64::decode(&line.unwrap()).unwrap())
.collect();
}
@@ -35,7 +32,7 @@ pub fn read_as_base64(filename: &str) -> Vec<u8> {
let fh = File::open(filename).unwrap();
return std::io::BufReader::new(fh)
.lines()
- .map(|line| line.unwrap().from_base64().unwrap())
+ .map(|line| base64::decode(&line.unwrap()).unwrap())
.collect::<Vec<Vec<u8>>>()
.concat();
}