Browse Source

Starting Cryptopals challenge 1

master
Benoît 2 years ago
commit
075cfc05d1
  1. 2
      set1/chal1/.gitignore
  2. 6
      set1/chal1/Cargo.lock
  3. 9
      set1/chal1/Cargo.toml
  4. 19
      set1/chal1/src/main.rs

2
set1/chal1/.gitignore

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

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

9
set1/chal1/Cargo.toml

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

19
set1/chal1/src/main.rs

@ -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));
}
}
Loading…
Cancel
Save