Starting Cryptopals challenge 1

master
Benoît 2020-01-03 19:16:43 +01:00
commit 075cfc05d1
4 changed files with 36 additions and 0 deletions

2
set1/chal1/.gitignore vendored 100644
View File

@ -0,0 +1,2 @@
target/
Cargo.lock

6
set1/chal1/Cargo.lock generated 100644
View File

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

View File

@ -0,0 +1,9 @@
[package]
name = "chal1"
version = "0.1.0"
authors = ["beneth <bmauduit@beneth.fr>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,19 @@
use std::env;
fn hex_to_char(s: &str) -> Result<char, std::num::ParseIntError> {
u8::from_str_radix(s, 16).map(|n| n as char)
}
fn main() {
let args: Vec<String> = env::args().collect();
let input = &args[1];
let char_vec: Vec<char> = input.chars().collect();
let split = &char_vec.chunks(2)
.map(|chunk| chunk.iter().collect::<String>())
.collect::<Vec<_>>();
for s in split {
println!("{:?}", hex_to_char(s));
}
}