Kodowanie Base64 konwertuje 8-bitowe dane binarne na 6-bitowe znaki przy użyciu zestawu 64 znaków ASCII (A-Z, a-z, 0-9, +, /). Każde 3 bajty danych wejściowych są konwertowane na 4 znaki Base64, co zwiększa rozmiar danych o około 33%.
- Step 1 - Group into 3-byte blocks: The input data is divided into groups of 3 bytes (24 bits).
- Step 2 - Split into 6-bit segments: Each 24-bit block is split into four 6-bit segments.
- Step 3 - Map to Base64 characters: Each 6-bit value (0-63) is mapped to one of 64 ASCII characters: A-Z (values 0-25), a-z (26-51), 0-9 (52-61), + (62), / (63).
- Step 4 - Padding: If the input length isn't divisible by 3, padding characters (=) are added to make the output length a multiple of 4.
Example: The string "cat" (ASCII: 99, 97, 116) encodes to "Y2F0". The bytes [99, 97, 116] become binary 01100011 01100001 01110100, which splits into 6-bit groups: 011000 110110 000101 110100, mapping to Y(24) 2(54) F(5) 0(52).