stage
This commit is contained in:
18
problems/p3/src/main.rs
Normal file
18
problems/p3/src/main.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use common::is_valid_english;
|
||||
|
||||
fn main() {
|
||||
let xored_cipher = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
|
||||
let cipher_bytes = hex::decode(xored_cipher).expect("decode error");
|
||||
for key in 0..(1 << 8) {
|
||||
let key = key as u8;
|
||||
// 对密文的每个字节应用异或操作,得到明文
|
||||
let plaintext: Vec<u8> = cipher_bytes.iter().map(|&byte| byte ^ key).collect();
|
||||
// 尝试将字节转换为字符串
|
||||
if let Ok(text) = std::str::from_utf8(&plaintext) {
|
||||
// 只有当转换成功时才调用is_valid_english
|
||||
if is_valid_english(text, None) {
|
||||
println!("Found valid sentence with key {}: {}", key, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user