commit 72a40f5ad9fda99eedec3ca2223fe2f511613812 Author: Thomas Lindner Date: Fri Sep 9 16:59:57 2016 +0200 solve Challenge 1 of Set 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..968f8e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*/*/target diff --git a/set1/hex2base64/Cargo.lock b/set1/hex2base64/Cargo.lock new file mode 100644 index 0000000..5663e53 --- /dev/null +++ b/set1/hex2base64/Cargo.lock @@ -0,0 +1,12 @@ +[root] +name = "hex2base64" +version = "0.1.0" +dependencies = [ + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-serialize" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" + diff --git a/set1/hex2base64/Cargo.toml b/set1/hex2base64/Cargo.toml new file mode 100644 index 0000000..ba31f91 --- /dev/null +++ b/set1/hex2base64/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "hex2base64" +version = "0.1.0" +authors = ["Thomas Lindner "] + +[dependencies] +rustc-serialize = "0.3" + +[[bin]] +name = "hex2base64" +path = "src/bin.rs" diff --git a/set1/hex2base64/src/bin.rs b/set1/hex2base64/src/bin.rs new file mode 100644 index 0000000..bf9fea4 --- /dev/null +++ b/set1/hex2base64/src/bin.rs @@ -0,0 +1,15 @@ +extern crate rustc_serialize; + +use rustc_serialize::hex::FromHex; +use rustc_serialize::base64::{STANDARD, ToBase64}; +use std::io::{BufRead, stdin}; + +fn main() { + let stdin = stdin(); + for line in stdin.lock().lines().filter_map(|x| x.ok()) { + match line.from_hex() { + Ok(v) => println!("{}", v.to_base64(STANDARD)), + Err(e) => println!("{}", e) + } + } +}