Introduction

Base64 encoding is a format designed to prevent communication “mishaps” during the transfer of binary information. It achieves this through the conversion of binary data and a “lookup table” — data is eventually made in a stream of ASCII characters, which can then be transmitted and decoded. On base 64 encoded data, the resultant string is always larger than the original (i.e. this is not a compression algorithm). Another important distinction is that base 64 does not encrypt any information — it uses a “standard” table of characters to encode and decode information. In other words, any base-64 string can be decoded, as long as the string was encoded using a standard set of characters (which the decoder can also understand). (What Is Base64 Encoding & Decoding?, n.d.)

Base64 Index Mapping Table

Base64 Encoding

The encoding algorithm is simple:

Take three character bytes from the input stream (24bits), divide them into four 6 bit parts and convert each 6 bit value according to the table above. Repeat this until no more input character bytes are left.

Decoding Base64

Length of a Base64 string

Due to the padding during encoding, the number of characters of a Base64 string is always divisable by four.

Decoding a Base64 string

The decoding process is the reverse of that of the encoding.

References