The CRC principle of the battle between the spear and the Shield

Source: Internet
Author: User
Tags final
In the previous section we introduced the flower instruction, but the flower instruction is one kind of very simple thing, basically enters the door the cracker all can deal with. Therefore, it is necessary for us to add better protection to our own software. A CRC checksum is one of the good ways to do this.

What is CRC? In fact, we all should not be unfamiliar with it, remember? Have you used compression software such as RAR and zip? Do they often give you an annoying "CRC error" message? I think you should understand, CRC is the value of block data, its full name is "cyclic redundancy Check", Chinese name is "cyclic redundancy code", "CRC checksum" is "cyclic redundancy check." (Wow, really clumsy, I hope you do not when I am Tang's monk, hehe.) ^_^)

What's the use of CRC? Its application scope is very extensive, the most common is in the network transmission carries on the proofreading of the information. In fact, we can apply it to the software protection, because its calculation is very very very strict. Strictly to what extent? As long as your program is changed to a byte (or even just a case change), its value will be different from the original. Hoho, is it very powerful? So just give you the "original" program to calculate the CRC value, stored in a place, and then randomly in the program to the file for CRC Checksum, and then the first generation and save the CRC value for comparison, if the equivalent of your program has not been modified/cracked, if not the case, Then it is possible that your program was infected with the virus, or was cracker with a 16-tool brute force.

Nonsense said, we first look at the CRC principle.

(CRC is difficult to implement, so specifically how to use it to protect the file, left to the next section.) )

First look at two formulas:


Type one: 9/3 = 3 (remainder = 0)
Type two: (9 + 2)/3 = 3 (remainder = 2)

In elementary school, we know that division is to subtract the divisor x times and then leave the remainder.
So the two equations above can be computed in binary terms: (what?) You don't have binary calculations? I pour ~ ~ ~ ~)

Type one:


1001--> 9
0011---> 3
---------
0110--> 6
0011---> 3
---------
0011--> 3
0011---> 3
---------
0000--> 0, remainder

Minus 3 times, so the quotient is 3, and the last time the result is 0, so the remainder is 0.

Type two:


1011--> 11
0011---> 3
---------
1000--> 8
0011---> 3
---------
0101--> 5
0011---> 3
---------
0010--> 2, remainder

Minus 3 times, so the quotient is 3, and the last time the result is 2, so the remainder is 2.

You see? Good, let's go on!

The rule of binary subtraction is that if you encounter a 0-1 situation, then to borrow 1 from the high, it becomes a (10+0) -1=1

What is the difference between CRC operations? Let's look at the following example:

This time with an equation of 30/9, but let the reader note the final remainder:


11110--> 30
1001---> 9
---------
1100--> 12 (strange, isn't it?) Why not 21? )
1001---> 9
--------
--> 3, remainder--> the crc!

Is the calculation of this equation very strange? It's not a direct minus, it's an XOR way to do it (programmers should be familiar with XOR) and finally get a remainder.

Yes, this is the CRC operation method, understand? CRC is the essence of the XOR operation, the operation of the process we do not care about it, because the operation of the final result is not meaningful; what we are really interested in is the last remainder, which is the CRC value.
To do a CRC operation we need to select a divisor, this divisor we call it "poly", the width W is the highest position, so I just cited the divisor 9, this poly 1001 W is 3, rather than 4, note that the highest bit is always 1. (Don't ask why, this is a rule)

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.