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.



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.