There is only one way to use PHP to crack the verification code, which is to collect the signatures of characters appearing in the verification code, and then find a way to separate the characters in the verification code. What kind of artificial intelligence is obviously something that PHP cannot do, so as long as you can collect all the signatures of the characters that appear in the verification code and find a way to separate the characters in the verification code, you can crack it. The anti-cracking idea mainly revolves around these two steps, using more characters, such as Chinese, and using more fonts and deformations, so that the same character has multiple feature codes, or there is no fixed feature code. Increase the difficulty of separating characters. The position, size and spacing of characters appearing in the verification code are not fixed. Interference pixels must be able to play a role. The following takes the verification code of a certain website as an example to explain how to crack the verification code through the above two steps. Note: Part of the code comes from phper "Baba", special thanks!
- /* Sort the numerical values and find the second most element, because the first most element is the background color, and the second most is the character color. In other words, if each character They all use different colors, or the background color is not so monotonous. How can I separate the character colors? */
- function getMostRepeated($array){
- $count = array_count_values($array);
- arsort($count);
- $keys = array_keys($count);
- return $keys[1];
- }
- / * Read the verification code image, read the pixel RGB into a two-dimensional array, and 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 pixel color of the center line, the center line will definitely cut into the characters. . .
- $colors[] = $color;
- }
- $mainColor = getMostRepeated($colors);//Separate 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 image is in italics. In order to facilitate character separation, it is converted into regular font, so using italics is useless. . .
- if($y < 16){
- $pos = 0;
- }elseif($y >= 16 && $y <= 20){
- $pos = 1;
- $pic[$y][0 ] = 0;
- }elseif($y >= 21 && $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 colors of interference pixels and characters are completely different, it is easy to separate the character color and set the character pixel point to 1, so at least part of the interference pixel color must be the same as the character color!
- if ($currentColor !== $mainColor) {
- $pic[$y][$x+$pos] = 0;
- }else{
- $pic[$y][$x+$pos] = 1;
- $flag = false;
- }
- }
- }
- return $pic;
- }
- // The legendary feature code
- $char = array(
- 'A'=>'000000000000000000010000000000000000001011000000000000000111110000000000000001110100000 000000001111100000000000000111110000000000001011100110000000000111110000110000000001110100000110000000111100000000110000 00011111100000011000000011111111000110000000000011111110110000000000000111111100000000000000000111111100000000000000011 11111000000000000000011111110000000000000000001110000000000000000000110',
- 'B'=>'11111111111111111111011111111111111 1111110111111111111111111110110000000110000000110110000000110000000110110000000110000000110110000001110000000110111000011 1110000001101111111110011000111100111111000111111100001110 100000000000000111101000',
- 'C'=>'000001011110 000000000000011111111111110000000111111111111100000011101000011111110000111000000000000111000110000000000000011000110000 00000000001110110000000000000001110110000000000000000110110000000000000000110110000000000000000011011000000000000000011011 0000000000000000110110000000000000001100011000000000000001100011000000000000011000',
- 'D '=>'111111111111111111110111111111111111111110111111111111111111110110000000000000000110110000000000000000110110000000000000000110110000000000000000110110000000000000000110110000000000000000110110000000000000000110111000000000000001110011000000000000011100011110000000000111100001111000000001111000000111111111111111000000011111111111100000000000111111110000000',
- 'E'=>'111111111111111111110111111111111111111110111111111111111111110110000000110000000110110000000110000000110110000000110000000110110000000110000000110110000000110000000110110000000110000000110110000000110000000110110000000000000000110000000000000000000110',
- 'F'=>'111111111111111111110111111111111111111110111111111111111111110110000000110000000000110000000110000000000110000000110000000000110000000110000000000110000000110000000000110000000110000000000110000000110000000000110000000000000000000',
- 'G'=>'000001011110000000000000011111111111110000000111111111111110000001110100001111111000011100000000000011100011000000000000001100011000000000000001110110000000000000001110110000000000000000110110000000000000000110110000000000000000110110000000000000000110110000000000000000110110000000001111111110011000000001111111100011000000001111111100',
- 'H'=>'111111111111111111110111111111111111111110111111111111111111110000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000111111111111111111110111111111111111111110111111111111111111110 ',
- 'I'=>'111111111111111111110111111111111111111110111111111111111111110',
- 'J'=>'111111111111111111111111111111111111111111111111111111111111110',
- 'K'=>'111111111111111111110111111111111111111110111111111111111111110000000000110000000000000000001110000000000000000011011000000000000001111001110000000000011110001111000000000111100000111100000001110000000001110000011100000000000111000111000000000000011100110000000000000001110100000000000000000110000000000000000000010',
- 'L'=>'111111111111111111110111111111111111111110111111111111111111110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110',
- 'M' =>'1111111111111111111101111111111111111111101111110000000000000001111110000000000000000011111111000000000000000011111 1000000000000000011111110000000000000000111110000000000000 000111111000000000000000001111000000000000000111110000000000 00101110000000000000011111000000000000111111010000000000001111000000000000001110000000000000000001111111111111111110111 1111111111111111011111111111111111110',
- 'N'=>'11111111110111111111111111111011111000000000000000011111 0000000000000000011110000000000000000001110000000000000000 00111100000000000000000011110000000000000000000111000000000000 00000000111000000000000000000111110000000000000000111110000000000000000001111000000000000000000000111101111111111111111111 1011111111111111111110',
- 'O'=>'0000010111100000000000000 111111111110000000011111111111100000011101000000111110000 111000000000000111000110000000000000110001100000000000000111 0110000000000000000110110000000000000000110110000000000000001 10110000000000000000110110000000000000000110111000000000000000110011000000000000011100011110000000000011110000111100000000 111100000011111111111111000000001111111110000000000011111 1110000000',
- 'P'=>'1111111111111111111011111111111111111 111011111111111111111101100000000110000000011000 000000110000000011000000000110000000011000000011100 000000011110000111000000000001111111100000000000011111111000000000000000111110000000000000',
- 'Q'=>'000001011110000000000000011111111111100000000111111111111110000001110100001111111000011100000000000011100011000000000000001100010000000000000001110110000000000000000110110000000000000000110110000000000000000110110000000000000000110110000000000000000110111000000000000000111011000000000000011111011110000000000111101001111000000001111001000111111111111110000000001111111111000000000000111111110000000',
- 'R'=>'111111111111111111110111111111111111111110111111111111111111110110000000110000000000110000000110000000000110000000110000000000110000000110000000000110000001111100000000111001011101111000000111111111001111110000011111111000011110000001110110000000111100000000000000000001110000000000000000001110000000000000000000010',
- 'S'=>'000111000000000001000001111110000000001100011111111000000001100011000111100000000110110000011110000000110110000001110000000110110000001110000000110110000000111000000110110000000011100011100111000000011111111100011000000001111111000000000000001111100000',
- 'T'=>'110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000111111111111111111110111111111111111111110111111111111111111110110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000',
- 'T '=>'110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000111111111111111111110111111111111111111110111111111111111111110110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000',//vt时t左边会被侵占掉一列
- 'U'=>'111111111111111110000111111111111111110000111111111111111111100000000000000000001100000000000000000001110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000001100000000000000000111100111111111111111111000111111111111111000000',
- 'V'=>'111100000000000000000111111000000000000000111111111000000000000000001111110000000000000000111111100000000000000000111111110000000000000001111111000000000000000001111110000000000000000011110000000000000001111110000000000010111101000000000000111110000000000001011111000000000000111111000000000000001110100000000000000111100000000000000000',//少读一列
- 'W'=>'111111000000000000000111111111000000000000111111111110000000000000000111111111110000000000001111111110000000000000001111111110000000000000000111110000000000000011111110000000001111111001000000011111111100000000011111110000000000000111111000000000000000111111000000000000000111111111110000000000000000111111111110000000000011111111111000000000000001111111110000000000000000111110000000000000011111110000000001111111001000000011111111100000000001111111000000000000111110100000000000000',
- 'X'=>'000000000000000000010110000000000000000110111100000000000011100111111000000000111000001111000000001100000000011110000011000000000000111110110000000000000111111100000000000000001111000000000000000001111100000000000001111001111000000000011110001111110000000111100000011110000001110000000000111100011100000000000001110110000000000000001110100000000000000000010',
- 'Y'=>'110000000000000000000111100000000000000000111111000000000000000001111000000000000000000011111000000000000000000111110000000000000000111111111111110000000000111111111110000000001111111111110000000011100000000000000001111000000000000000111100000000000000001110000000000000000011100000000000000000110000000000000000000100000000000000000000',
- 'Z'=>'000000000000000000110110000000000000011110110000000000001111110110000000000011111110110000000000111100110110000000011110000110110000000111100000110110000011111000000110110001111100000000110110011111000000000110110111100000000000110111110000000000000110111100000000000000110111000000000000000110',
- '0'=>'000001011110100000000000111111111111110000001111111101111110000011100000000000011100011000000000000001100110000000000000001110110000000000000000110110000000000000000110110000000000000000110111000000000000011100011111000000000111100001111111110111111000000011111111111100000000000111111110000000',
- '1'=>'001100000000000000110001100000000000000110011000000000000000110011000000000000000110011111111111111111110011111111111111111110111111111111111111110000000000000000000110000000000000000000110000000000000000000110000000000000000000110',
- '2'=>'000000000000000000110001100000000000111110011000000000000111110011000000000001101110110000000000011000110110000000000111000110110000000001110000110110000000011100000110111000000111000000110111100001111000000110011111111100000000110001111111000000000110000111110000000000110',
- '3'=>'011000000000000001100010000000000000001100110000000110000000110110000000110000000110110000000110000000110110000000110000000110110000001110000000110111000011011000001110111111111011000011100011111110001111111100001110100001111111000000000000000111101000',
- '4'=>'000000000000110000000000000000011110000000000000000111110000000000000001100110000000000001111000110000000000011110000110000000000111100000110000000001110000000110000000011100000000110000000111111111111111111110111111111111111111110111111111111111111110000000000000110000000000000000000110000000000000000000110000000',
- '5'=>'111111111000000001100111111111000000001110110000011000000000110110000011000000000110110000011000000000110110000011000000000110110000001100000000110110000001110000001110110000001110000111100110000000111111111100110000000011111111000110000000001111100000',
- '6'=>'000001011110111000000000011111111111110000001111111111111111000001110100101000011100011000001100000001100011000001000000001110110000011000000000110110000011000000000110110000011000000000110110000011100000000110110000011110000011100111000001111111111100011000000111111111000000000000001111000000',
- '7'=>'110000000000000000000110000000000000000010110000000000000111110110000000000011111110110000000000111111100110000000011111000000110000001111100000000110000011101000000000110001111000000000000110111110000000000000111110000000000000000111100000000000000000111000000000000000000',
- '8'=>'000000000000011110000000111000000111111000001111110011111111100011111111111100001100011000111111000001110110000011100000000110110000011110000000110110000001110000000110110000001111000000110111001011111000000110111111110011100011100011111110001111111100001110100001111111000000000000000111100000',
- '9'=>'000011111100000000000001111111110000001100001111111110000001100011100000111000000110111000000011100000110110000000001100000110110000000001100000110110000000001100000110110000000001100001100111000000011000011100011111000111001111000001111111111111111000000111111111111000000000000111111110000000',
- );
-
- $arr = fixImg("https://xxxxxxxxxx");// 哦,这里隐去某社区域名和验证码地址,为了支持https,你的php环境要开启openssl
- for($i = 0;$i < 10;$i++)
- unset($arr[$i]);// 前10行是空白
- $y = 0;// 采用从上到下,从左到右顺序读特征码,从第0行开始(实际是第10行)
- $len = 31;// 多读一行,JQ超过20行,且J后面几行占了上个字符的位置
- $code = array();// 分离出来的字符特征码
- $str = '';
- while($y < count($arr[10])){
- $flag = true;// 全0是空白竖线
- $line = '';
- for($i = 10;$i < $len;$i++){
- if($arr[$i][$y])
- $flag = false;
- $line .= $arr[$i][$y];
- }
- $isw = false;
- $isy = false;
- // 对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 = '00'.substr($line,2,strlen($line));
- if($str === '000000000000000000000')
- $str = '';
- $isw = false;
- }
- if($isy){
- $str = $line;
- if($str === '000000000000000000000')
- $str = '';
- $isy = false;
- }
- $y++;
-
- }
-
- // 输出字符
- foreach($code as $v){
- $match = false;
- foreach($char as $key => $v2){
- if($v === $v2){
- echo $key;
- $match = true;
- }
- }
- if(!$match)
- echo '?';// 没匹配到的字符输出问号
- }
-
复制代码
|