feat: finish 19
This commit is contained in:
7
problems/p19/Cargo.toml
Normal file
7
problems/p19/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "p19"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
base64 = { workspace = true }
|
||||
123
problems/p19/src/main.rs
Normal file
123
problems/p19/src/main.rs
Normal file
@@ -0,0 +1,123 @@
|
||||
// 使用瞪眼法判断
|
||||
// 结合gpt很快可以猜出来。
|
||||
use base64::{Engine as _, engine::general_purpose::STANDARD};
|
||||
use std::io::{Write, stdin, stdout};
|
||||
|
||||
fn guess(idx: usize, seq: &str) {
|
||||
let ciphers = [
|
||||
"SSBoYXZlIG1ldCB0aGVtIGF0IGNsb3NlIG9mIGRheQ==",
|
||||
"Q29taW5nIHdpdGggdml2aWQgZmFjZXM=",
|
||||
"RnJvbSBjb3VudGVyIG9yIGRlc2sgYW1vbmcgZ3JleQ==",
|
||||
"RWlnaHRlZW50aC1jZW50dXJ5IGhvdXNlcy4=",
|
||||
"SSBoYXZlIHBhc3NlZCB3aXRoIGEgbm9kIG9mIHRoZSBoZWFk",
|
||||
"T3IgcG9saXRlIG1lYW5pbmdsZXNzIHdvcmRzLA==",
|
||||
"T3IgaGF2ZSBsaW5nZXJlZCBhd2hpbGUgYW5kIHNhaWQ=",
|
||||
"UG9saXRlIG1lYW5pbmdsZXNzIHdvcmRzLA==",
|
||||
"QW5kIHRob3VnaHQgYmVmb3JlIEkgaGFkIGRvbmU=",
|
||||
"T2YgYSBtb2NraW5nIHRhbGUgb3IgYSBnaWJl",
|
||||
"VG8gcGxlYXNlIGEgY29tcGFuaW9u",
|
||||
"QXJvdW5kIHRoZSBmaXJlIGF0IHRoZSBjbHViLA==",
|
||||
"QmVpbmcgY2VydGFpbiB0aGF0IHRoZXkgYW5kIEk=",
|
||||
"QnV0IGxpdmVkIHdoZXJlIG1vdGxleSBpcyB3b3JuOg==",
|
||||
"QWxsIGNoYW5nZW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||||
"SGUsIHRvbywgaGFzIGJlZW4gY2hhbmdlZCBpbiBoaXMgdHVybiw=",
|
||||
"VHJhbnNmb3JtZWQgdXR0ZXJseTo=",
|
||||
"QSB0ZXJyaWJsZSBiZWF1dHkgaXMgYm9ybi4=",
|
||||
]
|
||||
.map(|x| STANDARD.decode(x).unwrap());
|
||||
let seq = seq.as_bytes();
|
||||
let key_stream: Vec<u8> = ciphers[idx].iter().zip(seq).map(|(a, b)| a ^ b).collect();
|
||||
let plaintexts: Vec<Vec<u8>> = ciphers
|
||||
.iter()
|
||||
.map(|cipher| {
|
||||
cipher
|
||||
.iter()
|
||||
.zip(key_stream.iter())
|
||||
.map(|(&a, &b)| a ^ b)
|
||||
.collect::<Vec<u8>>()
|
||||
})
|
||||
.collect();
|
||||
for (k, v) in plaintexts.iter().enumerate() {
|
||||
let v_str = String::from_utf8_lossy(v);
|
||||
println!("{k}: {v_str}");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
loop {
|
||||
print!("> ");
|
||||
stdout().flush().unwrap();
|
||||
let mut input = String::new();
|
||||
stdin().read_line(&mut input).expect("Failed to read input");
|
||||
let input = input.trim_end_matches(['\n', '\r']);
|
||||
let Some((idx, seq)) = input.split_once(" ") else {
|
||||
println!("Please enter two parts separated by space");
|
||||
continue;
|
||||
};
|
||||
|
||||
guess(idx.parse().unwrap(), seq);
|
||||
}
|
||||
|
||||
// 0: I have met them at close of day
|
||||
// 1: Coming with vivid faces
|
||||
// 2: From counter or desk among grey
|
||||
// 3: Eighteenth-century houses.
|
||||
// 4: I have passed with a nod of the head
|
||||
// 5: Or polite meaningless words,
|
||||
// 6: Or have lingered awhile and said
|
||||
// 7: Polite meaningless words,
|
||||
// 8: And thought before I had done
|
||||
// 9: Of a mocking tale or a gibe
|
||||
// 10: To please a companion
|
||||
// 11: Around the fire at the club,
|
||||
// 12: Being certain that they and I
|
||||
// 13: But lived where motley is worn:
|
||||
// 14: All changed, changed utterly:
|
||||
// 15: A terrible beauty is born.
|
||||
// 16: That woman's days were spent
|
||||
// 17: In ignorant good will,
|
||||
// 18: Her nights in argument
|
||||
// 19: Until her voice grew shrill.
|
||||
// 20: What voice more sweet than hers
|
||||
// 21: When young and beautiful,
|
||||
// 22: She rode to harriers?
|
||||
// 23: This man had kept a school
|
||||
// 24: And rode our winged horse.
|
||||
// 25: This other his helper and friend
|
||||
// 26: Was coming into his force;
|
||||
// 27: He might have won fame in the end,
|
||||
// 28: So sensitive his nature seemed,
|
||||
// 29: So daring and sweet his thought.
|
||||
// 30: This other man I had dreamed
|
||||
// 31: A drunken, vain-glorious lout.
|
||||
// 32: He had done most bitter wrong
|
||||
// 33: To some who are near my heart,
|
||||
// 34: Yet I number him in the song;
|
||||
// 35: He, too, has resigned his part
|
||||
// 36: In the casual comedy;
|
||||
// 37: He, too, has been changed in his turn
|
||||
// 38: Transformed utterly:
|
||||
// 39: A terrible beauty is born.
|
||||
}
|
||||
Reference in New Issue
Block a user