Refactor some more, done for now
This commit is contained in:
14
src/set3.rs
14
src/set3.rs
@@ -144,10 +144,10 @@ pub fn challenge19() {
|
||||
letters
|
||||
}
|
||||
|
||||
fn attack(ciphers: Vec<Bytes>) -> Vec<RefCell<Vec<u8>>> {
|
||||
fn attack(ciphers: &[Bytes]) -> Vec<RefCell<Vec<u8>>> {
|
||||
let ciphers_len = ciphers.len();
|
||||
let deciphered = vec![RefCell::new(vec![]); ciphers_len];
|
||||
let max_cipher_len = ciphers.iter().map(|c| c.len()).max().unwrap_or(0);
|
||||
let max_cipher_len = ciphers.iter().map(Bytes::len).max().unwrap_or(0);
|
||||
|
||||
for byte_index in 0..max_cipher_len {
|
||||
let letters = match byte_index {
|
||||
@@ -170,7 +170,7 @@ pub fn challenge19() {
|
||||
.collect();
|
||||
let mut possible_chars: Vec<HashSet<u8>> = ciphers
|
||||
.iter()
|
||||
.map(|_| HashSet::from_iter(letters.iter().cloned()))
|
||||
.map(|_| letters.iter().cloned().collect())
|
||||
.collect();
|
||||
|
||||
for i in 0..ciphers_len {
|
||||
@@ -180,8 +180,8 @@ pub fn challenge19() {
|
||||
}
|
||||
let xored = target_bytes[i].unwrap() ^ target_bytes[j].unwrap();
|
||||
let chars = lookup.get(&xored).unwrap().borrow();
|
||||
possible_chars[i] = possible_chars[i].intersection(&chars).cloned().collect();
|
||||
possible_chars[j] = possible_chars[j].intersection(&chars).cloned().collect();
|
||||
possible_chars[i] = possible_chars[i].intersection(&chars).copied().collect();
|
||||
possible_chars[j] = possible_chars[j].intersection(&chars).copied().collect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ pub fn challenge19() {
|
||||
let key = Bytes::from_utf8("YELLOW SUBMARINE");
|
||||
let encrypt = |plaintext: &Bytes| -> Bytes { ctr::encrypt(&key, 0, plaintext) };
|
||||
let ciphers: Vec<Bytes> = plaintexts.iter().map(encrypt).collect();
|
||||
let decrypts = attack(ciphers);
|
||||
let decrypts = attack(&ciphers);
|
||||
manual(&decrypts);
|
||||
let first_line = Bytes(decrypts[0].borrow().to_vec()).to_utf8();
|
||||
println!("[okay] Challenge 19: {first_line}");
|
||||
@@ -322,7 +322,7 @@ pub fn challenge22() {
|
||||
}
|
||||
|
||||
pub fn challenge23() {
|
||||
fn _temper(x: u32) -> u32 {
|
||||
const fn _temper(x: u32) -> u32 {
|
||||
const S: u32 = 7;
|
||||
const T: u32 = 15;
|
||||
const U: u32 = 11;
|
||||
|
||||
Reference in New Issue
Block a user