Last active
April 16, 2020 17:36
-
-
Save yvan-sraka/94638a5dd95f46cdaecf5ab4d7ed2676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut input = String::new(); | |
std::io::stdin().read_line(&mut input).unwrap(); | |
println!("Input: {}", input); | |
let result = input | |
.trim() | |
.chars() | |
.filter(|&ch| ch != '=') | |
.map(|ch| { | |
let ascii = ch as i8; | |
let convert = match ch { | |
'0'..='9' => ascii + 4, | |
'a'..='z' => ascii - 71, | |
'A'..='Z' => ascii - 65, | |
'+' => 62, | |
'/' => 63, | |
_ => panic!(), | |
}; | |
format!("{:#08b}", convert)[2..].to_string() | |
}) | |
.collect::<String>() | |
.chars() | |
.collect::<Vec<char>>() | |
.chunks(8) | |
.map(|chunk| { | |
let num_str = chunk.iter().collect::<String>(); | |
usize::from_str_radix(&num_str, 2).unwrap() as u8 | |
}) | |
.collect::<Vec<_>>(); | |
let output = String::from(std::str::from_utf8(&result).unwrap()); | |
println!("Output: {}", output); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main(){let mut i=String::new();std::io::stdin().read_line(&mut i).unwrap();println!("Input: {}",i);let r=i.trim().chars().filter(|&c|c!='=').map(|c|{let a=c as i8;let t=match c{'0'..='9'=>a+4,'a'..='z'=>a-71,'A'..='Z'=>a-65,'+'=>62,'/'=>63,_=>panic!()};format!("{:#08b}",t)[2..].to_string()}).collect::<String>().chars().collect::<Vec<char>>().chunks(8).map(|h|{let n=h.iter().collect::<String>();usize::from_str_radix(&n,2).unwrap() as u8}).collect::<Vec<_>>();let o=String::from(std::str::from_utf8(&r).unwrap());println!("Output: {}",o);} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment