Base64 encoding implementation principle Raiders

Principle of Base64 encoding

More to see Click here

This article will achieve:

  • Description of the ASCII character encoding Base64 encoding implementation principle
  • Description of non-ASCII character encoding Base64 encoding implementation principle

Cryptanalysis series:

  • Base64 encoding implementation principle (that is, the article)
  • Url Base64 encoding algorithm implementation principle (being issued in)
  • Series MD5 algorithm implementation principle (being issued in)
  • Series SHA algorithm implementation principle (being issued in)
  • Series MAC algorithm implementation principle (being issued in)
  • Symmetric encryption DES (is issued) is
  • Symmetric encryption AES (is issued) is
  • Password-based encryption PBE (being issued in)
  • Asymmetric encryption DH (is issued) is
  • The RSA asymmetric encryption (is issued) is

1 Brief

  • Base64 encoding and decoding operations algorithms, may serve as the encryption and decryption operations, as well as a character map acts as a key.
  • Base64 algorithm of the public, which is not contrary to the principle of Kirk Hoff, but acts as a key public character map, in direct violation of the principle of Kirk Hof
密码学上的柯克霍夫原则(Kerckhoffs's principle,也称为柯克霍夫假说、公理、或定律)系由奥古斯特·柯克霍夫在19世纪提出:即使密码系统的任何细节已为人悉知,只要密匙(key,又称密钥或秘钥)未泄漏,它也应是安全的。
复制代码
  • Base64 encryption algorithm can not be called, but the conversion law to comply with the single-table replacement algorithm.

2 Base64 index table

Base64 index table, we can understand the configuration encrypted ciphertext, the ciphertext characters selected "AZ, az, 0-9, +, /" 64 printable characters, which is the standard Base64 agreement. In everyday use, we will see the "=" or "==" number appears in Base64 encoded result, the "=" here appears as a fill character

['A', 'B', 'C', ... 'a', 'b', 'c', ... '0', '1', ... '+', '/']
复制代码

3 coding table

Simply, the plaintext string after a series of transformations, to generate the corresponding decimal value, with reference to the code table and then, the ciphertext is represented by a single character encoded by permutation table.

Here Insert Picture Description

4 Base64 encoding process implemented

Typically a string using Base64 encoded (encrypted), the character string is constituted, in the encoding process, as the basic unit to the characters shown in the following figure:

Here Insert Picture Description

Encoding process to achieve
  • Step: "M", "a", "n" corresponding to the ASCII value are 77,97,110, corresponding to the binary value 01001101,01100001,01101110 acquired. As shown in FIG second three rows, thereby to form a 24-bit binary string.
  • Step two: the binary code obtained do packet switching operation, each of the three 8-bit binary code to a group, every four to convert 6-bit binary code is a set (less than 6 when low complement 0) in FIG red box , a 24-bit bit group is divided into four groups of six each, which is a process of changing the packet, three 8-bit binary code and a length of four 6-bit binary code is 24,
  • The third step: the four 6-bit binary complement code obtained was added to two 6-bit binary code 0 high to form four 8-bit binary code, 0 is added 2 high, the composition of four 8-bit binary code, extended to 32 bits, four bytes at this time becomes: 00010011,00010110,00000101,00101110.
  • The fourth step The obtained four 8-bit binary code is converted into decimal code, in the above data, 00010011,00010110,00000101,00101110 correspond decimal value: 19,22,5,46. Fifth step: to obtain with the above decimal value (Base64 encoded index) in the lookup table Base64 encoding, respectively: T, W, F, u. So "Man" after Base64 encoding becomes: TWFu.
Less than the median case

Here Insert Picture Description

5 non-ASCII character encoding

ASCII code may be expressed in the range of 0-127 decimal character, corresponding to the binary range 0000 0000-01111111

ASCII code comprises digits, some control case letters and symbols, but not comprising a double-byte encoded characters, such as Chinese characters, with GB2312, GBK, UTF-8 encoding, etc., GB2312, GBK with two words section represents a character, UTF-8 represented by a three-byte characters.

Non-ASCII character encoding encryption implementation process

We have the string "secret" as an example

  • The first step obtains the encoded string "dense" utf-8 corresponding to the -27, -81, -122
  • Acquires the second step are utf-8 encoded (-27, -81, -122) corresponding to the binary code: 10000110 1,110,010,110,101,111
  • The third step of the above-described binary code into 4 groups 6 111 001 011 010 111 110 000 110
  • Moving towards the fourth 6-bit binary code 0 was added two high, the composition of four 8-bit binary code, adding two high 0,00111001 00011010 0,011,111,000,000,110
  • A fifth step of acquiring said binary code corresponding decimal code 5726626
  • A sixth step in the lookup table Base64 encoding, respectively 5 a + G

String "dense" obtained after Base64 encoded character string "5a + G"

6 Analysis

Here Base64 (6 th power of 2 is 64) characters transformed into 8-bit binary code to 6 units of the packet conversion represents a character, become Base64. Similarly, Base32 is a packet 5, Base16 is to use four packets.

So Base32, Base16 encoding process will clear out.

Guess you like

Origin juejin.im/post/5dc0b1305188255fd468f599