BASE32 Plus decryption algorithm and actual combat

Source: Internet
Author: User
Tags base64 character set md5

Through the solitary water around the city Daniel recommendation, side dishes I play a hacker game, one of the close encounter a cipher, it looks like base64 code, but through Base64 decoding garbled. Later considered is MD5 (base64), and then through the Base64 decoding and then turn 16 into the system to get 5 digits, it is obvious, not MD5 (base64). And then tried the combination of Base64 and other encodings is also wrong. Later looked closely at the lonely water around the city, the main points of the Knowledge master, only to know that this cipher is through the BASE32 code to get, no wonder the solution does not come out. Oh. But Google and Baidu a lap did not find a decoding tool, there is no way to look to do it yourself. Finally through the study finally superficial understanding of BASE32 encryption and decryption principle, so there is this article.

I. Introduction of BASE32 Data encoding

BASE32 This data encoding mechanism, mainly used to encode binary data into a visible string, the encoding rule is: arbitrarily given a binary data, with 5 bits (bit) for a set of segmentation (Base64 6 bit (bit) as a group), Each group that is sliced is encoded to get 1 visible characters. The total number of characters in the BASE32 encoded table Character Set is 25 = 32, which is also the origin of the Base32 name. Here is a standard BASE32 code table I found on the Internet, as shown in table 1.

Table 1 standard Base Code table

Second, the Code demonstration

The following is a concrete example of the coding process for Base32. This is encoded with the "Bhst" string. The steps are as follows:
1. After the character "Bhst" takes the ASCII code, it is converted into binary to get "1100010,1101000,1110011,1110100," a total of four bytes, 28 bit binary string. Note: Since BASE32 is the encoding for transmitting 8bit bytes of code, the binary highest bit plus 0 for the "bhst" string is changed to 8 bits per group. A binary string consisting of 32 bits.
2. Slice the binary string corresponding to "Bhst" strings with 5 bits. Get the "01100,01001,10100,00111,00110,11101,00000" binary string "bhst" of 7 bytes. Note: The binary string for each group is less than 5 and is supplemented with 0.
3. Calculate the decimal for each set of binary strings, and then refer to the Standard BASE32 encoding table to find out the corresponding encoded characters, combining redact. Note: When the last grouping bit is less than 4, it is encoded with the character "=".

As shown in table 2:

Table 2 takes 5 bits for a set of 7-byte entries
Standard Base32 characters for binary strings and corresponding

Third, instance decoding

The coded algorithm knows, and wants to decode the reverse back on it. Here is an example of the ciphertext in the game. The "i4ag6aa=" step is as follows:
1, the cipher text in the encoded characters (against the standard BASE32 encoding table) to find the corresponding decimal code value. are: 8 28 0 6 30 0 0, respectively.
2, the decimal code value to convert to binary, less than 5 bit with 0 supplement. Gets: 01000,11100,00000,00110,11110,00000,00000
3. Combine the binary string of each group, and slice it with 8 bit for a group. Gets: 01000111,00000000,01101111,00000000,00000000
4, restore each set of binary string to get plaintext ASCII code 71 0 111 0 0, revert to character is go.

As shown in table 3:

Iv. Summary

Through the research on the algorithm of BASE32 encryption and decryption, the last pass. This article is written by personal understanding, and if there are any mistakes, ask the brothers to point out.

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.