From 9e31b6cc5b116800d280d23317f8b2eb3a191754 Mon Sep 17 00:00:00 2001 From: Alivecow Date: Tue, 3 Dec 2024 22:58:10 +0100 Subject: [PATCH] fix: Add ciphertext padding to gcm_crack --- src/tasks/tasks01/gcm_crack.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tasks/tasks01/gcm_crack.rs b/src/tasks/tasks01/gcm_crack.rs index 6cabe38..5dc2236 100644 --- a/src/tasks/tasks01/gcm_crack.rs +++ b/src/tasks/tasks01/gcm_crack.rs @@ -34,7 +34,10 @@ struct Message { fn parse_message(val: &Value) -> Result<(Message, Polynomial)> { let ciphertext_text: String = serde_json::from_value(val["ciphertext"].clone())?; - let ciphertext_bytes: Vec = BASE64_STANDARD.decode(ciphertext_text)?; + let mut ciphertext_bytes: Vec = BASE64_STANDARD.decode(ciphertext_text)?; + if ciphertext_bytes.len() % 16 != 0 { + ciphertext_bytes.append(vec![0u8; 16 - (ciphertext_bytes.len() % 16)].as_mut()); + } let ciphertext_chunks: Vec = ciphertext_bytes .chunks(16) .into_iter()