Add base64 explanation
This commit is contained in:
parent
ccfaaf39f8
commit
635e727741
1 changed files with 6 additions and 0 deletions
|
@ -111,6 +111,12 @@ func HexToBase64(hexValue string) (base64 string, success bool) {
|
||||||
|
|
||||||
originals := plainBuffer[i : i+3]
|
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
|
first := originals[0] >> 2
|
||||||
second := (0b00110000 & (originals[0] << 4)) ^ (originals[1] >> 4)
|
second := (0b00110000 & (originals[0] << 4)) ^ (originals[1] >> 4)
|
||||||
third := (0b00111100 & (originals[1] << 2)) ^ (originals[2] >> 6)
|
third := (0b00111100 & (originals[1] << 2)) ^ (originals[2] >> 6)
|
||||||
|
|
Loading…
Add table
Reference in a new issue