commit 4f28bbdad6216a99f1a9e5bc4850fecb614153e7
parent 8e913b62fe182585a959e45496e0d71707bf3157
Author: Jared Tobin <jared@jtobin.ca>
Date: Tue, 20 Dec 2016 22:29:45 +1300
Single byte xor tool.
Diffstat:
3 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/lib/single_byte_xor/Cargo.lock b/lib/single_byte_xor/Cargo.lock
@@ -0,0 +1,14 @@
+[root]
+name = "single_byte_xor"
+version = "0.1.0"
+dependencies = [
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-serialize"
+version = "0.3.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b"
diff --git a/lib/single_byte_xor/Cargo.toml b/lib/single_byte_xor/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "single_byte_xor"
+version = "0.1.0"
+authors = ["Jared Tobin <jared@jtobin.ca>"]
+
+[dependencies]
+
+rustc-serialize = "0.3.0"
diff --git a/lib/single_byte_xor/src/main.rs b/lib/single_byte_xor/src/main.rs
@@ -0,0 +1,41 @@
+extern crate rustc_serialize as serialize;
+
+use serialize::hex::{FromHex};
+use std::env;
+use std::io::{self, Read};
+use std::string::String;
+
+fn main() {
+ // deal with args
+ let args: Vec<String> = env::args().collect();
+
+ if args.len() != 2 {
+ println!("USAGE: echo FOO | ./single_byte_xor BYTE");
+ return ()
+ }
+
+ let supplied_string = &args[1];
+ let supplied_byte = supplied_string.clone().into_bytes()[0];
+
+ // deal with stdin
+ let mut buffer = String::new();
+
+ io::stdin().read_to_string(&mut buffer)
+ .expect("single_byte_xor: bad input");
+
+ let mut decoded = match buffer.from_hex() {
+ Err(err) => panic!("single_byte_xor: {}", err),
+ Ok(val) => val,
+ };
+
+ for byte in decoded.iter_mut() { *byte ^= supplied_byte; }
+
+ let decrypted = match String::from_utf8(decoded) {
+ Err(err) => panic!("single_byte_xor: {}", err),
+ Ok(val) => val,
+ };
+
+ println!("original: {}", &buffer);
+ println!("xored with: {} ({})", supplied_string, supplied_byte);
+ println!("decrypted: {}", decrypted);
+}