PHP-Made Simple verification code recognition Codes _php instance

Source: Internet
Author: User

have been trying to write this, after a long time today's interest to simply record.

Verification Code

Fully automatic distinction between computer and human public Turing Test (English: Completely automated-Turing test to tell Computers and humans Apart, referred to as CAPTCHA), commonly known as the verification Code, is a public automatic program that distinguishes users from computers and people. In the CAPTCHA test, the computer that serves as the server automatically generates a problem to be answered by the user. This problem can be generated and judged by the computer, but it must be solved only by humans. Because the computer cannot answer the CAPTCHA problem, the user who answers the question can be considered human.
About the Encyclopedia

The simple point is that the randomly generated characters, output in a picture [here do not consider other forms of drag/SMS verification code, etc.].

Common types

Ideas

This article is only for demonstration use, so take the first picture verification code as an example.

Each point on the picture has its RGB value, through the color picker can be obtained, the naked eye can see that the map verification code is pure digital solid background

The RGB value of the Authenticode background color is seen by the Color picker (212,214,204)

Realize

Here we'll use the PHP imagecolorsforindex function to get the RGB values of all the points in the picture:

$url = ' http://210.32.33.91:8080/reader/captcha.php ';
$im = Imagecreatefromgif ($url);
Imagegif ($im, ' 1.gif ');
$rgbArray = Array ();
$res = $im;
$size = getimagesize ($url);

$wid = $size [' 0 '];
$hid = $size [' 1 '];
for ($i = 0; $i < $hid + + $i) {for
 ($j = 0; $j < $wid; + + $j) {
  $rgb = Imagecolorat ($res, $j, $i);
  $rgbArray [$i] [$j] = Imagecolorsforindex ($res, $rgb);
 }

The results are as follows:

You might want to ask, what's the use? Below we change a way to display the data for the background color output , verify the Code region output , and then look at:

for ($i = 0; $i < $hid; $i + +) {for
 ($j = 0; $j < $wid; $j + +) {
  
  if ($rgbArray [$i] [$j] [' red '] = = 212) {
   echo '-';
  } else {
   echo ';
  }
 }}
 echo "<br>";
}

Effect:

This is not very clear.

But you may still have a question, though you can see it, but how much do you know?

Let's analyze the following:


Each verification code is directly spaced 4 lattice, left and right 6/10 lattice, up and down 16/10 space.

Let's get rid of these distractions and we can see more clearly:



Is it clear? Maybe someone will ask how much you really want to know about the number in the picture.

Well, next to my ideas, we'll just have to switch to 0 and 1, and these numbers are fixed, so that we can get 0-9 of each word in each area 8*10 has 0 and 1,

We're going to do every 8 slices, get rid of the 4-grid spacing, and loop through 0-9 of the 01 combined values:

 $dic = Array (' 00011000001111000110011011000011110000111100001111000011011001100011110000011000 ' => 0, ' 00011000001110000111100000011000000110000001100000011000000110000001100001111110 ' => 1, ' 00111100011001101100001100000011000001100000110000011000001100000110000011111111 ' => 2, ' 01111100110001100000001100000110000111000000011000000011000000111100011001111100 ' => 3, ' 00000110000011100001111000110110011001101100011011111111000001100000011000000110 ' => 4, ' 11111110110000001100000011011100111001100000001100000011110000110110011000111100 ' => 5, ' 00111100011001101100001011000000110111001110011011000011110000110110011000111100 ' => 6, ' 11111111000000110000001100000110000011000001100000110000011000001100000011000000 ' => 7, ' 00111100011001101100001101100110001111000110011011000011110000110110011000111100 ' => 8, ' 
00111100011001101100001111000011011001110011101100000011010000110110011000111100 ' => 9); 

After the 10 combinations, each resolution of the picture RGB to the corresponding array value of the value of the verification code. Here's a demo:

Finally for accuracy, take 100 loops to see:

Haha, accuracy rate 100%

Written in the last

The purpose of this article is to allow web developers to be aware of security when generating Authenticode, and do not use it for illegal purposes.

Code already in GitHub:

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.