1
0
This commit is contained in:
2025-06-20 11:23:21 +08:00
commit b5601aef8c
47 changed files with 1829 additions and 0 deletions

25
problems/p2/src/main.rs Normal file
View File

@@ -0,0 +1,25 @@
fn fixed_xor(buf1: &[u8], buf2: &[u8]) -> Result<Vec<u8>, String> {
if buf1.len() != buf2.len() {
return Err(format!(
"输入缓冲区长度不匹配: {} vs {}",
buf1.len(),
buf2.len()
));
}
Ok(buf1
.iter()
.zip(buf2.iter())
.map(|(&b1, b2)| b1 ^ b2)
.collect())
}
fn main() -> Result<(), String> {
let string1 = hex::decode("1c0111001f010100061a024b53535009181c").expect("error");
let string2 = hex::decode("686974207468652062756c6c277320657965").expect("error");
let xor_string = fixed_xor(&string1, &string2)?;
// 将结果转换为十六进制字符串
let hex_result = hex::encode(&xor_string);
println!("{}", hex_result);
Ok(())
}