The basic principle of Cyclic Redundancy checksum (CRC) is:
After the K-bit information code is combined with the R-bit verification code, the length of the entire code is N bits. Therefore, this encoding is also called (n, k) code. For a given (n, k) code, it can be proved that there is a polynomial g (x) whose maximum power is N-K = R ). The checksum code for K-bit information can be generated based on g (x), while G (x) is called the polynomial of CRC code generation.
The specific generation process of the Verification Code is as follows: assume that the sending information is represented by the information polynomial C (x), and C (X) is shifted to the r bit, it can be expressed as C (x) * 2R, in this way, the right side of C (x) will be blank out of the r bit, which is the position of the verification code. The remainder obtained by dividing C (x) * 2r by the generated polynomial g (x) is the verification code.
It is very simple. It should be noted that MoD 2 Division is the addition of mod 2 in the division process. mod 2 addition is actually an exclusive or operation we are familiar with, that is, the addition does not consider carry. The formula is:
0 + 0 = 1 + 1 = 0 + 0 = 0 + 1 = 1
That is to say, 'ise' is true, while 'nonise' is false.
The obtained theorem is as follows: A + B + B = A, that is, the 'modulo 2 shares' AND THE 'modulo 2 add' direct value table are identical.
With addition and subtraction, the modulo 2 division can be defined, and the CRC check code can be generated using the generated polynomial g (x.
For example, g (x) = X4 + X3 + X2 + 1, (110), the CRC code generated by information code is:
G (x) = X4 + X3 + X2 + 1: (all from right to left) X4 is the fifth digit is 1, because there is no X1, so 2nd digits is 0.
11101 | 11101 (set a = 1100000, B =)
Take the first 5 digits of B. The value 11000 is different from that of a. The value 101 is obtained.
101 + 00 not obtained by B get 10100
Then it is different from a or get 01001
That is, the remainder is 1001.
The remainder is 1001, so the CRC code is
The standard CRC code is, CRC-CCITT and CRC-16, and their generative polynomials are:
CRC-CCITT = x ^ 16 + x ^ 12 + x ^ 5 + 1
CRC-16 = x ^ 16 + x ^ 15 + x ^ 2 + 1
2. Code Implementation