solve Challenge 1 of Set 1

This commit is contained in:
Thomas Lindner 2016-09-09 16:59:57 +02:00
commit 72a40f5ad9
4 changed files with 39 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*/*/target

12
set1/hex2base64/Cargo.lock generated Normal file
View file

@ -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"

View file

@ -0,0 +1,11 @@
[package]
name = "hex2base64"
version = "0.1.0"
authors = ["Thomas Lindner <thomas.lindner@fau.de>"]
[dependencies]
rustc-serialize = "0.3"
[[bin]]
name = "hex2base64"
path = "src/bin.rs"

View file

@ -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)
}
}
}