Using PHP to crack the verification code, there is only one way, is to collect the characters in the verification Code character code, and then try to isolate the characters in the verification code. What artificial intelligence, obviously PHP can not do, so, as long as the verification code to collect the characters in the character code, and can find a way to isolate the characters in the verification code, it can be cracked. The idea of anti-cracking is also mainly around these two steps, using more characters, such as using Chinese, using more fonts and transformations, so that the same character has multiple signatures, or no fixed signature code. To increase the difficulty of separating characters, the characters appear in the verification code position is not fixed, the size is not fixed, the spacing is not fixed, interference pixels to be able to play a role. Below take a website verification code as an example, explain how to crack the verification code through the above two steps. Note: Part of the code from the Phper "Strike Bar", special thanks!
- /* Sort numeric values to find the second most element because the first number of elements is the background color, the second is the character colors, in other words, if each character uses a different color, or the background color is not so monotonous, how can I separate out the character color? */
- function getmostrepeated ($array) {
- $count = Array_count_values ($array);
- Arsort ($count);
- $keys = Array_keys ($count);
- return $keys [1];
- }
- /* Read the CAPTCHA picture and read the pixel RGB into the two-dimensional array, then separate the valid characters */
- function Fiximg ($url) {
- $img = Imagecreatefrompng ($url);
- $with = Imagesx ($img);
- $height = Imagesy ($img);
- $middle = $height/2;
- $colors = Array ();
- for ($i = 0; $i < $with; + + $i) {
- $color = Imagecolorat ($img, $i, $middle);//Read the median pixel color, the midline will definitely cut to the character ...
- $colors [] = $color;
- }
- $mainColor = getmostrepeated ($colors);//separating out the character color
- $pic = Array ();
- for ($x = 0; $x < $with; + + $x) {
- $flag = true;
- for ($y = 0; $y < $height; + + $y) {
- $currentColor = Imagecolorat ($img, $x, $y);
- $pos = 0;//The original picture is italic, in order to facilitate the segmentation of characters, turn into traditional, so it is useless to use italics ...
- if ($y < 16) {
- $pos = 0;
- }elseif ($y >= && $y <= 20) {
- $pos = 1;
- $pic [$y][0] = 0;
- }elseif ($y >= && $y <= 26) {
- $pos = 2;
- $pic [$y][0] = $pic [$y][1] = 0;
- }else{
- $pos = 3;
- $pic [$y][0] = $pic [$y][1] = $pic [$y][2] = 0;
- }
- Because the interference pixel and the color of the character is completely different, easy to separate out the character color, the character pixel point 1, so the interference pixel color at least part of the color is the same as the character line!
- if ($currentColor!== $mainColor) {
- $pic [$y] [$x + $pos] = 0;
- }else{
- $pic [$y] [$x + $pos] = 1;
- $flag = false;
- }
- }
- }
- return $pic;
- }
- The legendary signature code
- $char = Array (
- ' A ' and ' = ' 0000000000000000000100000000000000000101100000000000000011111000000000000000111010000000000000111110000000000000011111100 0000000000101110011000000000011111000011000000000111010000011000000011110000000011000000011111100000011000000011111111100 0110000000000011111110110000000000000111111110000000000000000111111110000000000000001111111000000000000000011111110000000 000000000001110000000000000000000110 ',
- ' B ' and ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000001101100000001100000001101100000001100000 0011011000000111000000011011100001111100000011011111111100110001111001111111000111111110000111010000111111110000000000000 0111101000 ',
- ' C ' = ' 0000010111100000000000000111111111111100000001111111111111100000011101000011111110000111000000000000111000110000000000000 0110001100000000000000111011000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110110000000000000000110110000000000000001100011000000000000001100011000000000000011000 ',
- ' D ' and ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000000000000001101100000000000000001101100000000000000 0011011000000000000000011011000000000000000011011000000000000000011011000000000000000011011100000000000000111001100000000 0000011100011110000000000111100001111000000001111000000111111111111111000000011111111111100000000000111111110000000 ' ,
- ' E ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000001101100000001100000001101100000001100000 0011011000000011000000011011000000011000000011011000000011000000011011000000011000000011011000000000000000011000000000000 0000000110 ',
- ' F ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000000001100000001100000000001100000001100000 00000110000000110000000000110000000110000000000110000000110000000000110000000110000000000110000000000000000000 ' ,
- ' G ' and ' = ' 0000010111100000000000000111111111111100000001111111111111100000011101000011111110000111000000000000111000110000000000000 0110001100000000000000111011000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110110000000000000000110110000000001111111110011000000001111111100011000000001111111100 ',
- ' H ' = ' 1111111111111111111101111111111111111111101111111111111111111100000000001100000000000000000001100000000000000000001100000 0000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011 0000000000000000000110000000000111111111111111111110111111111111111111110111111111111111111110 ',
- ' I ' = ' 111111111111111111110111111111111111111110111111111111111111110 ',
- ' J ' = ' 111111111111111111111111111111111111111111111111111111111111110 ',
- ' K ' = ' 1111111111111111111101111111111111111111101111111111111111111100000000001100000000000000000011100000000000000000110110000 0000000000111100111000000000001111000111100000000011110000011110000000111000000000111000001110000000000011100011100000000 0000011100110000000000000001110100000000000000000110000000000000000000010 ',
- ' L ' = ' 1111111111111111111101111111111111111111101111111111111111111100000000000000000001100000000000000000001100000000000000000 0011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000 0000000110 ',
- ' M ' = ' 1111111111111111111101111111111111111111101111110000000000000001111111000000000000000001111111100000000000000001111110000 0000000000001111111110000000000000000111111000000000000000011111110000000000000000011110000000000000001111110000000000001 0111000000000000001111100000000000011111101000000000000111110000000000000011100000000000000000111111111111111111110111111 111111111111110111111111111111111110 ',
- ' N ' = ' 1111111111111111111101111111111111111111101111100000000000000000111110000000000000000001111000000000000000000011100000000 0000000000011110000000000000000001111000000000000000000011100000000000000000000111000000000000000000111110000000000000000 0111110000000000000000001111000000000000000000011110111111111111111111110111111111111111111110 ',
- ' O ' and ' = ' 0000010111100000000000000111111111111000000001111111111111100000011101000000111110000111000000000000111000110000000000000 0110001100000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110111000000000000000110011000000000000011100011110000000000111100001111000000001111000000111111111111111000000001 111111111100000000000111111110000000 ',
- ' P ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000000110000000001100000000110000000001100000000110000 0000011000000011100000000011000000011100000000011110000111000000000001111111110000000000001111111100000000000000011111000 0000000000 ',
- ' Q ' and ' = ' 0000010111100000000000000111111111111000000001111111111111100000011101000011111110000111000000000000111000110000000000000 0110001000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110111000000000000000111011000000000000011111011110000000000111101001111000000001111001000111111111111110000000001 111111111000000000000111111110000000 ',
- ' R ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000000001100000001100000000001100000001100000 0000011000000011000000000011000000111110000000011100101110111100000011111111100111111000001111111100001111000000111011000 0000111100000000000000000001110000000000000000001110000000000000000000010 ',
- ' S ' ' = ' 0001110000000000010000011111100000000011000111111110000000011000110001111000000001101100000111100000001101100000011100000 0011011000000111000000011011000000011100000011011000000001110001110011100000001111111110001100000000111111100000000000000 1111100000 ',
- ' T ' = ' 1100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000 0000011000000000000000000011111111111111111111011111111111111111111011111111111111111111011000000000000000000011000000000 0000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000 ' ,
- ' T ' = ' 1100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000 0000011111111111111111111011111111111111111111011111111111111111111011000000000000000000011000000000000000000011000000000 0000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000 ',// VT, the left side of T will be overrun with a column.
- ' U ' = ' 1111111111111111100001111111111111111100001111111111111111111000000000000000000011000000000000000000011100000000000000000 0011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000110000000000000 0000111100111111111111111111000111111111111111000000 ',
- ' V ' = ' 1111000000000000000001111110000000000000001111111110000000000000000011111100000000000000001111111000000000000000001111111 1000000000000000111111100000000000000000111111000000000000000001111000000000000000111111000000000001011110100000000000011 1110000000000001011111000000000000111111000000000000001110100000000000000111100000000000000000 ',//less read a column
- ' W ' = ' 1111110000000000000001111111110000000000001111111111100000000000000001111111111100000000000011111111100000000000000011111 1111000000000000000011111000000000000001111111000000000111111100100000001111111110000000001111111000000000000011111100000 0000000000111111000000000000000111111111110000000000000000111111111110000000000011111111111000000000000001111111110000000 000000000111110000000000000011111110000000001111111001000000011111111100000000001111111000000000000111110100000000000000 ' ,
- ' X ' = ' 0000000000000000000101100000000000000001101111000000000000111001111110000000001110000011110000000011000000000111100000110 0000000000011111011000000000000011111110000000000000000111100000000000000000111110000000000000111100111100000000001111000 1111110000000111100000011110000001110000000000111100011100000000000001110110000000000000001110100000000000000000010 ' ,
- ' Y ' = ' 1100000000000000000001111000000000000000001111110000000000000000011110000000000000000000111110000000000000000001111100000 0000000000011111111111111000000000011111111111000000000111111111111000000001110000000000000000111100000000000000011110000 0000000000001110000000000000000011100000000000000000110000000000000000000100000000000000000000 ',
- ' Z ' = ' 0000000000000000001101100000000000000111101100000000000011111101100000000000111111101100000000001111001101100000000111100 0011011000000011110000011011000001111100000011011000111110000000011011001111100000000011011011110000000000011011111000000 0000000110111100000000000000110111000000000000000110 ',
- ' 0 ' = ' 0000010111101000000000001111111111111100000011111111011111100000111000000000000111000110000000000000011001100000000000000 0111011000000000000000011011000000000000000011011000000000000000011011100000000000001110001111100000000011110000111111111 0111111000000011111111111100000000000111111110000000 ',
- ' 1 ' = ' 0011000000000000001100011000000000000001100110000000000000001100110000000000000001100111111111111111111100111111111111111 11110111111111111111111110000000000000000000110000000000000000000110000000000000000000110000000000000000000110 ' ,
- ' 2 ' = ' 0000000000000000001100011000000000001111100110000000000001111100110000000000011011101100000000000110001101100000000001110 0011011000000000111000011011000000001110000011011100000011100000011011110000111100000011001111111110000000011000111111100 0000000110000111110000000000110 ',
- ' 3 ' = ' 0110000000000000011000100000000000000011001100000001100000001101100000001100000001101100000001100000001101100000001100000 0011011000000111000000011011100001101100000111011111111101100001110001111111000111111110000111010000111111100000000000000 0111101000 ',
- ' 4 ' = ' 0000000000001100000000000000000111100000000000000001111100000000000000011001100000000000011110001100000000000111100001100 0000000011110000011000000000111000000011000000001110000000011000000011111111111111111111011111111111111111111011111111111 1111111110000000000000110000000000000000000110000000000000000000110000000 ',
- ' 5 ' = ' 1111111110000000011001111111110000000011101100000110000000001101100000110000000001101100000110000000001101100000110000000 0011011000000110000000011011000000111000000111011000000111000011110011000000011111111110011000000001111111100011000000000 1111100000 ',
- ' 6 ' = ' 0000010111101110000000000111111111111100000011111111111111110000011101001010000111000110000011000000011000110000010000000 0111011000001100000000011011000001100000000011011000001100000000011011000001110000000011011000001111000001110011100000111 1111111100011000000111111111000000000000001111000000 ',
- ' 7 ' = ' 1100000000000000000001100000000000000000101100000000000001111101100000000000111111101100000000001111111001100000000111110 0000011000000111110000000011000001110100000000011000111100000000000011011111000000000000011111000000000000000011110000000 0000000000111000000000000000000 ',
- ' 8 ' = ' 0000000000000111100000001110000001111110000011111100111111111000111111111111000011000110001111110000011101100000111000000 0011011000001111000000011011000000111000000011011000000111100000011011100101111100000011011111111001110001110001111111000 1111111100001110100001111111000000000000000111100000 ',
- ' 9 ' = ' 0000111111000000000000011111111100000011000011111111100000011000111000001110000001101110000000111000001101100000000011000 0011011000000000110000011011000000000110000011011000000000110000110011100000001100001110001111100011100111100000111111111 1111111000000111111111111000000000000111111110000000 ',
- );
- $arr = fiximg ("https://xxxxxxxxxx");//Oh, there is a community domain name and verification code address, in order to support HTTPS, your PHP environment to open OpenSSL
- for ($i = 0; $i < $i + +)
- Unset ($arr [$i]);//The first 10 lines are blank
- $y = 0;//with a top-to-bottom, left-to-right sequential read signature, starting at line No. 0 (actually line 10th)
- $len = 31;//read one line more than 20 lines in JQ, and J after a few lines occupy the position of the last character
- $code = Array ();//separated character signatures
- $str = ";
- while ($y < count ($arr [10])) {
- $flag = true;//Full 0 is a blank vertical line
- $line = ";
- for ($i = ten; $i < $len; $i + +) {
- if ($arr [$i] [$y])
- $flag = false;
- $line. = $arr [$i] [$y];
- }
- $ISW = false;
- $isy = false;
- Special handling of VW
- if ($str = = = $char [' V '] | | $str = = = = $char [' W ']) {
- $flag = true;
- $ISW = true;
- }elseif ($str = = = $char [' Y '] | | $str = = = $char [' A ']) {
- $isy = true;
- $flag = true;
- }
- if ($flag) {
- if (strlen ($STR) > 21)
- $code [] = $STR;
- $str = ";
- }else{
- $str. = $line;
- }
- if ($ISW) {
- $str = ' xx '. substr ($line, 2,strlen ($line));
- if ($str = = = ' 000000000000000000000 ')
- $str = ";
- $ISW = false;
- }
- if ($isy) {
- $str = $line;
- if ($str = = = ' 000000000000000000000 ')
- $str = ";
- $isy = false;
- }
- $y + +;
- }
- Output character
- foreach ($code as $v) {
- $match = false;
- foreach ($char as $key = + $v 2) {
- if ($v = = = $v 2) {
- Echo $key;
- $match = true;
- }
- }
- if (! $match)
- echo '? '; /no match to the character output question mark
- }
Copy Code |