# Do automatic posting procedures-Baidu bar code algorithm to verify

Source: Internet
Author: User
Baidu | procedure | algorithm | Verification Code First, enter a stick, such as "Virus Bar", address is Http://post.baidu.com/f?kw=virus

Figure 1

As you can see, there is a form at the bottom of the page that allows anonymous postings. If you want to write a program that automatically posts, the only difficulty is the verification code.

Figure 2

Next look at the page source code, found that the verification code is a picture, generated by the script. The link to the verification code picture is shaped like http://post-js.baidu.com/cgi-bin/c?[ P1]&[P2], where P1 and P2 are two random integers.

Figure 3

All the verification code pictures have 4 Arabic numerals on them, which are mixed with some noise points. Unfortunately, these noise points are not randomly generated, for example,http://post-js.baidu.com/cgi-bin/c?0&0 and http://post-js.baidu.com/cgi-bin/c? 65536&0 These two links will produce two identical pictures.

Verify that the number above the picture can be computed directly from the link address that generated it. The C code for the formula is as follows:

P1 >>= 8;
P2 >>= 8;
P1 = (P1 & 0xff) + ((P1 >>) << 8);
P2 = (P2 & 0xff) + ((P2 >>) << 8);
result = (P1 + (P2 << 16))% 10000;

The link address shown in Figure 3 can generate the verification code in Figure 2, for this example, the two integers in the link:

P1 = 695327974, p2 = 1581465364
P1 = p1/256 = 695327974/256 = 2716124
P2 = p2/256 = 1581465364/256 = 6177599
P1 = p1%256 + p1/65536*256 = 2716124%256 + 2716124/65536*256 = 10716
P2 = p2%256 + p2/65536*256 = 6177599%256 + 6177599/65536*256 = 24127
result = (P1 + p2*65536)%10000 = (10716 + 24127*65536)%10000 = 1581197788%10000 = 7788

This is the verification code 7788 in Figure 2.

Related Keywords:
Related Article ## Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019 ## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China ## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD