summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-03-15 03:50:50 -0400
committerJesse Luehrs <doy@tozt.net>2015-03-15 03:50:50 -0400
commit7bafc19e5f367cc795ad08672359e7fce0329539 (patch)
tree6a38590adba375dc39e5a1ee304a5b1a22843053
parent80c8da8a5b56535a2566409c95590b086b9888c9 (diff)
downloadmatasano-7bafc19e5f367cc795ad08672359e7fce0329539.tar.gz
matasano-7bafc19e5f367cc795ad08672359e7fce0329539.zip
problem 1 done
-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);
+ }
+}