Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. use failure::Error;
  2. use std::char;
  3.  
  4. fn bytes_from_hex_str(hex: &str) -> Result<Vec<u8>, Error> {
  5. let mut bytes = vec![];
  6.  
  7. for i in (0..hex.len()).step_by(2) {
  8. let byte = u8::from_str_radix(&hex[i..=(i + 1)], 16)?;
  9. bytes.push(byte);
  10. }
  11.  
  12. Ok(bytes)
  13. }
  14.  
  15.  
  16. fn main() {
  17. let s = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736".to_string();
  18.  
  19. let bytes = bytes_from_hex_str(&s).expect("must work");
  20. for c in b"0123456789abcdef" {
  21. let phrase = bytes.iter().map(|&b|
  22. format!("{}", char::from_u32( (b ^ c) as u32 ).unwrap() )).collect::<String>();
  23. println!("{} - {}", c, phrase);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement