Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. use failure::Error;
  2. use std::str;
  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. fn main() {
  16. let s = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736".to_string();
  17.  
  18. let bytes = bytes_from_hex_str(&s).expect("must work");
  19. for c in (b'a'..b'z').chain(b'0'..b'9').chain(b'A'..b'Z') {
  20. let phrase = bytes.iter().map(|&b| b ^ c).collect::<Vec<_>>();
  21.  
  22. println!("{} - {}", c, str::from_utf8(&phrase).unwrap());
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement