commit 075cfc05d13df3bada60413edcc9df47ba8d51f4 Author: beneth Date: Fri Jan 3 19:16:43 2020 +0100 Starting Cryptopals challenge 1 diff --git a/set1/chal1/.gitignore b/set1/chal1/.gitignore new file mode 100644 index 0000000..4470988 --- /dev/null +++ b/set1/chal1/.gitignore @@ -0,0 +1,2 @@ +target/ +Cargo.lock \ No newline at end of file diff --git a/set1/chal1/Cargo.lock b/set1/chal1/Cargo.lock new file mode 100644 index 0000000..3792a21 --- /dev/null +++ b/set1/chal1/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "chal1" +version = "0.1.0" + diff --git a/set1/chal1/Cargo.toml b/set1/chal1/Cargo.toml new file mode 100644 index 0000000..4564721 --- /dev/null +++ b/set1/chal1/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "chal1" +version = "0.1.0" +authors = ["beneth "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/set1/chal1/src/main.rs b/set1/chal1/src/main.rs new file mode 100644 index 0000000..c9bc164 --- /dev/null +++ b/set1/chal1/src/main.rs @@ -0,0 +1,19 @@ +use std::env; + +fn hex_to_char(s: &str) -> Result { + u8::from_str_radix(s, 16).map(|n| n as char) +} + +fn main() { + let args: Vec = env::args().collect(); + let input = &args[1]; + + let char_vec: Vec = input.chars().collect(); + let split = &char_vec.chunks(2) + .map(|chunk| chunk.iter().collect::()) + .collect::>(); + + for s in split { + println!("{:?}", hex_to_char(s)); + } +}