Base encoding

Base encoding is a frequently used to represent arbitrary binary data as text. On the outside, it seems like Base encoding could be used to encrypt data, however, Base64 encoding only transforms data into a text format. Anyone can decode it!

Base64 example

The name “Base64” comes from the fact that Base64 uses 64 possible values for representing binary data as we are using 6 bits (2^6 = 64) to represent a single Base64 character.

So let’s say you have the word “one”, this is how it works:

First step: Ascii conversion. ASCII represents characters with eight bit. You can find a conversion table here.

As you can see, the corresponding decimal is value is :

  • 111 for “o”
  • 110 for “n”
  • 101 for “e”

Second step: Binary conversion. We now convert those Ascii numbers to their binary values with this tool :

  • 01101111 for “111”
  • 01101110 for “110”
  • 01100101 for “101”

The word one is “one” is now : 01101111-01101110-01100101

Third step: Base64 encoding. We can now look at the Base64 conversion table to finish the encoding but as Base64 encodes binary data with six bits instead of eight, we need to pack our bits in groups of 6.

We had this 01101111-01101110-01100101 and we now group them by 6, so it become: 011011-110110-111001-100101

With the table, we convert:

  • b for “011011”
  • 2 for “110110”
  • 5 for “111001”
  • l for “100101”