Base64 | Base32 | BASE16 Coding and decoding summary

Source: Internet
Author: User
Tags base64 character set control characters printable characters uppercase letter

1.BASE64 Introduction

Base64 is a representation of binary data based on 64 printable characters. Base64 encoding generally has the following two uses:

A) All binaries can thus be converted to printable text encoding (all become ASCII printable characters) and edited using text software;

b) The ability to encrypt text simply.

Plainly speaking, a string or file consisting of 0 and 1 can be converted to a string of any combination of 64 characters according to the code rules of Base64.

2.BASE64 Coding Rules

The so-called Base64, that is to choose 64 characters----lowercase letter A-Z, uppercase letter A-Z, number 0-9, the symbol "+", "/" (plus the "=" as the pad word, is actually 65 characters)----as a basic character set. All other symbols are then converted to the characters in this character set.

Specifically, the conversion method can be divided into four steps:

The first step, each three bytes as a group, is a total of 24 bits The
second step, the 24 bits divided into four groups, each group has 6 bits
third step, in front of each group two 00, expanded to 32 bits, that is, four bytes
fourth step, according to the following table, To get the corresponding symbol for each byte that is expanded, this is the encoded value of the BASE64
The following is the BASE64 Encoding mapping table:



An example of 3.BASE64 encoding

Give a concrete example of how the English word man turns into a Base64 code:



Note:

(1) Base64 converts three bytes into four bytes, so Base64 encoded text will be about One-third larger than the original text

(2) For less than 3 bytes of the east, you need to add the Base64 code in the pad character to add

(3) BASE64 encoding is reversible, so there is Base64 encoding encode and decoding decode

(4) Base64 is mainly not encryption, its main purpose is to convert some binary numbers into ordinary characters for network transmission (because some binary characters in the transport protocol belong to the control characters, can not be transmitted directly). In addition, there are some systems that can only use ASCII characters. Base64 is a way to convert non-ASCII characters of data into ASCII characters. Base64 is not actually a cryptographic decryption algorithm in the security domain. Although sometimes it is often seen that the so-called Base64 encryption decryption. In fact, Base64 can only be regarded as a coding algorithm, the data content is encoded to fit the transmission. Although the original text also becomes a character format that cannot be seen after the Base64 encoding, this approach is very elementary and simple.


4.base32 and Base16

In the base family there are Base32 and Base16, in fact Base32/base16 and Base64 purpose is the same, but the specific coding rules are not the same. BASE32 encoding converts a binary file into text consisting of 32 ASCII characters; BASE16 encoding converts a binary file into a 16-character text.

Attach the BASE32 encoding mapping table as follows:


Attach the BASE16 encoding mapping table as follows:



The learning materials are referenced in:

Http://www.ruanyifeng.com/blog/2008/06/base64.html

http://blog.csdn.net/instruder/article/details/5963344

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.