Docsity

Understanding Base 64 Encoding: Converting Binary Data to ASCII, Slides of Computer Networks

Partial preview of the text

Download Understanding Base 64 Encoding: Converting Binary Data to ASCII and more Slides Computer Networks in PDF only on Docsity!

Base 64 Encoding

What is Base 64 Encoded Data?

In programming, Base64 is a group of binary-to-text encoding schemes that represent

binary data (more specifically, a sequence of 8-bit bytes) in an ASCII string format by

translating the data into a radix-64 representation. The term Base64 originates from a

specific MIME content transfer encoding. Each non-final Base64 digit represents exactly 6

bits of data. Three 8-bit bytes (i.e., a total of 24 bits) can therefore be represented by four 6-

bit Base64 digits.

What does Base 64 Encoding Do?

Base 64 Encoding takes a stream of characters and converts them to characters that belong

to the universal ASCII character set. Once a stream of characters has been converted to

characters that belong to the universal ASCII character set (Base 64 encoded) they can be

transported with ease over the Internet using the e-mail protocols.

Encoding "Mary had" to Base 64

From our example we got,

ASCII text Mary had

Hex representation of text 4D 61 72 79 20 68 61 64

Bit representation of text grouped by

bytes

Bit representation of text in groups

of 6 bits

Decimal representation of text in

groups of 6 bits

Base 64 encoded string. TWFyeSBoYWQ=

Encode Algorithm

Let’s see some steps for Base 64 ENCODING Algorithm:

Step:

First, we need to split the string letter by letter. Thus, necessary groups.

Step:

Next we need to convert each group to binary.

To do this, for each letter we need to find the corresponding binary value in

the ASCII table. After that, we have some groups of ones and zeros.

Step:

Now concatenate all the binary values together (that is, glue all the groups along

and make sure we get a total of

(Number of Groups*8) characters).

Encode Algorithm

Step:

Then, divide the resulting string into groups so that each one has 6 characters (if

the last group has less than 6 characters, we need to fill it with zeros until it

reaches the desired length). Well and good.

Step:

At this step we have to convert six-bit bytes into eight-bit bytes. To do this,

prepend the prefix “00” (two zeros) in front of each group.

Step:

There we have to convert each group from binary to decimal by finding its

corresponding decimal value in the ASCII table. If we did everything right, each

group will be transformed into its integer number.

Example:

For example, you have the “BUET” string and want to convert it to

Base64:

Step:

First, we need to split the string letter by letter. Thus, we got groups.

B
U
E
T

Example:1(cont...)

Step:

Next we need to convert each group to binary.

To do this, for each letter we need to find the corresponding binary value in

the ASCII table. Now, we have 4 groups of ones and zeros.

Example:1(cont...)

Step:

At this step we have to convert six-bit bytes into eight-bit bytes. To do this,

prepend the prefix “00” (two zeros) in front of each group.

 00010000

 00000000

Example:1(cont...)

Step:

There we have to convert each group from binary to decimal by finding its

corresponding decimal value in the ASCII table. If we did everything right, each

group will be transformed into its integer number as follows.

Base 64 Characters Table:

Example:1(cont...)

Step:

The final chord, concatenate all letters to get the Base64 string: QlVFVA

To summarize, we learned that encoding “BUET” to Base64 yields the result

“QlVFVA”. As we can see, this is a very simple process and you can encode text

to Base64 even by hand. I hope that you managed to get the right encoding

result.