commit 158c922afe7b6d1d73d5eec7c165fff80948b59b
parent 5519cc7eabdcf39a0abae1537cac3d1e2f173081
Author: Jared Tobin <jared@jtobin.ca>
Date: Mon, 28 Aug 2017 21:02:32 +1200
Updates.
Diffstat:
4 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -5,5 +5,6 @@ authors = ["Jared Tobin <jared@jtobin.ca>"]
[dependencies]
base64 = "0.6.0"
-hex = "0.2.0"
+clap = "2.26.0"
+hex = "0.2.0"
diff --git a/docs/s1.md b/docs/s1.md
@@ -102,12 +102,37 @@ Five doesn't go far:
Twenty-nine does it:
$ KEYSIZE=29
- $ echo $INPUTHEX | ./bin/rotate $KEYSIZE | parallel -k ./bin/charfreq | less
- $ xxd -r -p <<< "$INPUTHEX" | \
- ./bin/repeating_key_xor "tERMINATOR x bRING THE NOISE" | \
- xxd -r -p | less
-
-Shift by 32 for readability:
+ $ echo $INPUTHEX | ./bin/rotate $KEYSIZE | \
+ parallel -k 'echo -n {} | ./bin/break_single_byte_xor -r'
+ T (84)
+ e (101)
+ r (114)
+ m (109)
+ i (105)
+ n (110)
+ a (97)
+ t (116)
+ o (111)
+ r (114)
+ (32)
+ X (88)
+ : (58)
+ (32)
+ B (66)
+ r (114)
+ i (105)
+ n (110)
+ g (103)
+ (32)
+ t (116)
+ h (104)
+ e (101)
+ (32)
+ n (110)
+ o (111)
+ i (105)
+ s (115)
+ e (101)
$ xxd -r -p <<< "$INPUTHEX" | \
./bin/repeating_key_xor "Terminator X: Bring the noise" | \
diff --git a/lib/break_single_byte_xor/Cargo.toml b/lib/break_single_byte_xor/Cargo.toml
@@ -5,3 +5,4 @@ authors = ["Jared Tobin <jared@jtobin.ca>"]
[dependencies]
hex = "0.2.0"
+clap = "2.26.0"
diff --git a/lib/break_single_byte_xor/src/main.rs b/lib/break_single_byte_xor/src/main.rs
@@ -1,6 +1,8 @@
+extern crate clap;
extern crate hex;
+use clap::{App, Arg};
use self::hex::{FromHex, ToHex};
use std::collections::HashMap;
use std::io::{self, Read};
@@ -188,13 +190,31 @@ pub fn break_single_byte_xor(string: &str) -> (u8, String) {
}
fn main() {
+ let args = App::new("break_single_byte_xor")
+ .version("0.1.0")
+ .about("Break single-byte XOR")
+ .arg(Arg::with_name("return-byte")
+ .short("r")
+ .long("return-key")
+ .help("return encrypting byte"))
+ .get_matches();
+
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer)
.expect("single_byte_xor: bad input");
+ let return_byte = match args.occurrences_of("return-byte") {
+ 0 => false,
+ _ => true,
+ };
+
let message = break_single_byte_xor(&buffer);
- println!("{}", message.1);
+ if return_byte {
+ println!("{} ({})", message.0 as char, message.0);
+ } else {
+ println!("{}", message.1);
+ }
}