summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml3
-rw-r--r--src/bin/1.rs25
3 files changed, 40 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..252e8fe
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,12 @@
+[root]
+name = "matasano"
+version = "0.0.1"
+dependencies = [
+ "rustc-serialize 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-serialize"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
diff --git a/Cargo.toml b/Cargo.toml
index 1cc4858..dcde5e8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,3 +3,6 @@
name = "matasano"
version = "0.0.1"
authors = ["Jesse Luehrs <doy@tozt.net>"]
+
+[dependencies]
+rustc-serialize = "0.3.3"
diff --git a/src/bin/1.rs b/src/bin/1.rs
new file mode 100644
index 0000000..3378e65
--- /dev/null
+++ b/src/bin/1.rs
@@ -0,0 +1,25 @@
+extern crate "rustc-serialize" as serialize;
+
+use std::io::prelude::*;
+use serialize::base64::{ToBase64,STANDARD};
+use serialize::hex::FromHex;
+
+fn main () {
+ loop {
+ let mut buf = [0; 6];
+ let len = match std::io::stdin().read(&mut buf) {
+ Ok(n) => n,
+ Err(e) => panic!("{}", e),
+ };
+ if len == 0 {
+ break;
+ }
+ let hex = std::str::from_utf8(&buf[..len]).unwrap();
+ let bytes = match hex.from_hex() {
+ Ok(b) => b,
+ Err(e) => panic!("{}", e),
+ };
+ let base64 = bytes.to_base64(STANDARD);
+ print!("{}", base64);
+ }
+}