From 635e72774117113a9ef629fcd66a18ee68277030 Mon Sep 17 00:00:00 2001 From: mvvasilev Date: Mon, 28 Oct 2024 00:12:43 +0200 Subject: [PATCH] Add base64 explanation --- set1/challenge_1.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/set1/challenge_1.go b/set1/challenge_1.go index 49ab843..19c79ee 100644 --- a/set1/challenge_1.go +++ b/set1/challenge_1.go @@ -111,6 +111,12 @@ func HexToBase64(hexValue string) (base64 string, success bool) { originals := plainBuffer[i : i+3] + // Base64 splits up 3 bytes into 4 by first taking all 24 bits of the original 3 bytes and splitting them evenly across 4 6-bit words + // Example: byte A: 0bAAAAAAAA, byte B: 0bBBBBBBBB, byte C: 0bCCCCCCCC + // Base64 Result: 0b00AAAAAA, 0b00AABBBB, 0b00BBCCCC, 0b00CCCCCC + // This expands the size of the original data by ~33% + // If the byte size of the original data is not divisible by 3, the missing bytes are padded out to 0s and the padding character = is used to the end of the base64 string + first := originals[0] >> 2 second := (0b00110000 & (originals[0] << 4)) ^ (originals[1] >> 4) third := (0b00111100 & (originals[1] << 2)) ^ (originals[2] >> 6)