Thursday, October 16, 2008

Mail Attachment Algorithm - Base64

Base64 is the algorithm used to attach the files with the mail. It basically converts each byte (8-bit) to 6-bit byte, the remaining 2-bits will get added to the next byte. If you save the mail which has the attachment and look into it, you will find a octet-stream for each individual file attached. Let me explain how that octet stream formed.

11001111-11110011-10111111 - regular byte stream (3 bytes of 8 bits. Total 8*3=24 bits)

00110011 - 00111111 - 00001110-00111111 - Base64 stream (4 bytes of 6 bits. Total 6*4=24 bits)

If you observe the above 3 bytes are converted to 4 bytes, each byte contains 6 bits. Hence this algorithm is named as Base64 algorithm.

--
Anand
anand.sadasivam@googlemail.com