Verification code cracking and anti-cracking ideas

Source: Internet
Author: User
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!
  1. /* 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? */
  2. function getmostrepeated ($array) {
  3. $count = Array_count_values ($array);
  4. Arsort ($count);
  5. $keys = Array_keys ($count);
  6. return $keys [1];
  7. }
  8. /* Read the CAPTCHA picture and read the pixel RGB into the two-dimensional array, then separate the valid characters */
  9. function Fiximg ($url) {
  10. $img = Imagecreatefrompng ($url);
  11. $with = Imagesx ($img);
  12. $height = Imagesy ($img);
  13. $middle = $height/2;
  14. $colors = Array ();
  15. for ($i = 0; $i < $with; + + $i) {
  16. $color = Imagecolorat ($img, $i, $middle);//Read the median pixel color, the midline will definitely cut to the character ...
  17. $colors [] = $color;
  18. }
  19. $mainColor = getmostrepeated ($colors);//separating out the character color
  20. $pic = Array ();
  21. for ($x = 0; $x < $with; + + $x) {
  22. $flag = true;
  23. for ($y = 0; $y < $height; + + $y) {
  24. $currentColor = Imagecolorat ($img, $x, $y);
  25. $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 ...
  26. if ($y < 16) {
  27. $pos = 0;
  28. }elseif ($y >= && $y <= 20) {
  29. $pos = 1;
  30. $pic [$y][0] = 0;
  31. }elseif ($y >= && $y <= 26) {
  32. $pos = 2;
  33. $pic [$y][0] = $pic [$y][1] = 0;
  34. }else{
  35. $pos = 3;
  36. $pic [$y][0] = $pic [$y][1] = $pic [$y][2] = 0;
  37. }
  38. 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!
  39. if ($currentColor!== $mainColor) {
  40. $pic [$y] [$x + $pos] = 0;
  41. }else{
  42. $pic [$y] [$x + $pos] = 1;
  43. $flag = false;
  44. }
  45. }
  46. }
  47. return $pic;
  48. }
  49. The legendary signature code
  50. $char = Array (
  51. ' A ' and ' = ' 0000000000000000000100000000000000000101100000000000000011111000000000000000111010000000000000111110000000000000011111100 0000000000101110011000000000011111000011000000000111010000011000000011110000000011000000011111100000011000000011111111100 0110000000000011111110110000000000000111111110000000000000000111111110000000000000001111111000000000000000011111110000000 000000000001110000000000000000000110 ',
  52. ' B ' and ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000001101100000001100000001101100000001100000 0011011000000111000000011011100001111100000011011111111100110001111001111111000111111110000111010000111111110000000000000 0111101000 ',
  53. ' C ' = ' 0000010111100000000000000111111111111100000001111111111111100000011101000011111110000111000000000000111000110000000000000 0110001100000000000000111011000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110110000000000000000110110000000000000001100011000000000000001100011000000000000011000 ',
  54. ' D ' and ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000000000000001101100000000000000001101100000000000000 0011011000000000000000011011000000000000000011011000000000000000011011000000000000000011011100000000000000111001100000000 0000011100011110000000000111100001111000000001111000000111111111111111000000011111111111100000000000111111110000000 ' ,
  55. ' E ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000001101100000001100000001101100000001100000 0011011000000011000000011011000000011000000011011000000011000000011011000000011000000011011000000000000000011000000000000 0000000110 ',
  56. ' F ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000000001100000001100000000001100000001100000 00000110000000110000000000110000000110000000000110000000110000000000110000000110000000000110000000000000000000 ' ,
  57. ' G ' and ' = ' 0000010111100000000000000111111111111100000001111111111111100000011101000011111110000111000000000000111000110000000000000 0110001100000000000000111011000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110110000000000000000110110000000001111111110011000000001111111100011000000001111111100 ',
  58. ' H ' = ' 1111111111111111111101111111111111111111101111111111111111111100000000001100000000000000000001100000000000000000001100000 0000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011 0000000000000000000110000000000111111111111111111110111111111111111111110111111111111111111110 ',
  59. ' I ' = ' 111111111111111111110111111111111111111110111111111111111111110 ',
  60. ' J ' = ' 111111111111111111111111111111111111111111111111111111111111110 ',
  61. ' K ' = ' 1111111111111111111101111111111111111111101111111111111111111100000000001100000000000000000011100000000000000000110110000 0000000000111100111000000000001111000111100000000011110000011110000000111000000000111000001110000000000011100011100000000 0000011100110000000000000001110100000000000000000110000000000000000000010 ',
  62. ' L ' = ' 1111111111111111111101111111111111111111101111111111111111111100000000000000000001100000000000000000001100000000000000000 0011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000 0000000110 ',
  63. ' M ' = ' 1111111111111111111101111111111111111111101111110000000000000001111111000000000000000001111111100000000000000001111110000 0000000000001111111110000000000000000111111000000000000000011111110000000000000000011110000000000000001111110000000000001 0111000000000000001111100000000000011111101000000000000111110000000000000011100000000000000000111111111111111111110111111 111111111111110111111111111111111110 ',
  64. ' N ' = ' 1111111111111111111101111111111111111111101111100000000000000000111110000000000000000001111000000000000000000011100000000 0000000000011110000000000000000001111000000000000000000011100000000000000000000111000000000000000000111110000000000000000 0111110000000000000000001111000000000000000000011110111111111111111111110111111111111111111110 ',
  65. ' O ' and ' = ' 0000010111100000000000000111111111111000000001111111111111100000011101000000111110000111000000000000111000110000000000000 0110001100000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110111000000000000000110011000000000000011100011110000000000111100001111000000001111000000111111111111111000000001 111111111100000000000111111110000000 ',
  66. ' P ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000000110000000001100000000110000000001100000000110000 0000011000000011100000000011000000011100000000011110000111000000000001111111110000000000001111111100000000000000011111000 0000000000 ',
  67. ' Q ' and ' = ' 0000010111100000000000000111111111111000000001111111111111100000011101000011111110000111000000000000111000110000000000000 0110001000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011000000000 0000000110111000000000000000111011000000000000011111011110000000000111101001111000000001111001000111111111111110000000001 111111111000000000000111111110000000 ',
  68. ' R ' = ' 1111111111111111111101111111111111111111101111111111111111111101100000001100000000001100000001100000000001100000001100000 0000011000000011000000000011000000111110000000011100101110111100000011111111100111111000001111111100001111000000111011000 0000111100000000000000000001110000000000000000001110000000000000000000010 ',
  69. ' S ' ' = ' 0001110000000000010000011111100000000011000111111110000000011000110001111000000001101100000111100000001101100000011100000 0011011000000111000000011011000000011100000011011000000001110001110011100000001111111110001100000000111111100000000000000 1111100000 ',
  70. ' T ' = ' 1100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000 0000011000000000000000000011111111111111111111011111111111111111111011111111111111111111011000000000000000000011000000000 0000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000 ' ,
  71. ' T ' = ' 1100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000 0000011111111111111111111011111111111111111111011111111111111111111011000000000000000000011000000000000000000011000000000 0000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000 ',// VT, the left side of T will be overrun with a column.
  72. ' U ' = ' 1111111111111111100001111111111111111100001111111111111111111000000000000000000011000000000000000000011100000000000000000 0011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000110000000000000 0000111100111111111111111111000111111111111111000000 ',
  73. ' V ' = ' 1111000000000000000001111110000000000000001111111110000000000000000011111100000000000000001111111000000000000000001111111 1000000000000000111111100000000000000000111111000000000000000001111000000000000000111111000000000001011110100000000000011 1110000000000001011111000000000000111111000000000000001110100000000000000111100000000000000000 ',//less read a column
  74. ' W ' = ' 1111110000000000000001111111110000000000001111111111100000000000000001111111111100000000000011111111100000000000000011111 1111000000000000000011111000000000000001111111000000000111111100100000001111111110000000001111111000000000000011111100000 0000000000111111000000000000000111111111110000000000000000111111111110000000000011111111111000000000000001111111110000000 000000000111110000000000000011111110000000001111111001000000011111111100000000001111111000000000000111110100000000000000 ' ,
  75. ' X ' = ' 0000000000000000000101100000000000000001101111000000000000111001111110000000001110000011110000000011000000000111100000110 0000000000011111011000000000000011111110000000000000000111100000000000000000111110000000000000111100111100000000001111000 1111110000000111100000011110000001110000000000111100011100000000000001110110000000000000001110100000000000000000010 ' ,
  76. ' Y ' = ' 1100000000000000000001111000000000000000001111110000000000000000011110000000000000000000111110000000000000000001111100000 0000000000011111111111111000000000011111111111000000000111111111111000000001110000000000000000111100000000000000011110000 0000000000001110000000000000000011100000000000000000110000000000000000000100000000000000000000 ',
  77. ' Z ' = ' 0000000000000000001101100000000000000111101100000000000011111101100000000000111111101100000000001111001101100000000111100 0011011000000011110000011011000001111100000011011000111110000000011011001111100000000011011011110000000000011011111000000 0000000110111100000000000000110111000000000000000110 ',
  78. ' 0 ' = ' 0000010111101000000000001111111111111100000011111111011111100000111000000000000111000110000000000000011001100000000000000 0111011000000000000000011011000000000000000011011000000000000000011011100000000000001110001111100000000011110000111111111 0111111000000011111111111100000000000111111110000000 ',
  79. ' 1 ' = ' 0011000000000000001100011000000000000001100110000000000000001100110000000000000001100111111111111111111100111111111111111 11110111111111111111111110000000000000000000110000000000000000000110000000000000000000110000000000000000000110 ' ,
  80. ' 2 ' = ' 0000000000000000001100011000000000001111100110000000000001111100110000000000011011101100000000000110001101100000000001110 0011011000000000111000011011000000001110000011011100000011100000011011110000111100000011001111111110000000011000111111100 0000000110000111110000000000110 ',
  81. ' 3 ' = ' 0110000000000000011000100000000000000011001100000001100000001101100000001100000001101100000001100000001101100000001100000 0011011000000111000000011011100001101100000111011111111101100001110001111111000111111110000111010000111111100000000000000 0111101000 ',
  82. ' 4 ' = ' 0000000000001100000000000000000111100000000000000001111100000000000000011001100000000000011110001100000000000111100001100 0000000011110000011000000000111000000011000000001110000000011000000011111111111111111111011111111111111111111011111111111 1111111110000000000000110000000000000000000110000000000000000000110000000 ',
  83. ' 5 ' = ' 1111111110000000011001111111110000000011101100000110000000001101100000110000000001101100000110000000001101100000110000000 0011011000000110000000011011000000111000000111011000000111000011110011000000011111111110011000000001111111100011000000000 1111100000 ',
  84. ' 6 ' = ' 0000010111101110000000000111111111111100000011111111111111110000011101001010000111000110000011000000011000110000010000000 0111011000001100000000011011000001100000000011011000001100000000011011000001110000000011011000001111000001110011100000111 1111111100011000000111111111000000000000001111000000 ',
  85. ' 7 ' = ' 1100000000000000000001100000000000000000101100000000000001111101100000000000111111101100000000001111111001100000000111110 0000011000000111110000000011000001110100000000011000111100000000000011011111000000000000011111000000000000000011110000000 0000000000111000000000000000000 ',
  86. ' 8 ' = ' 0000000000000111100000001110000001111110000011111100111111111000111111111111000011000110001111110000011101100000111000000 0011011000001111000000011011000000111000000011011000000111100000011011100101111100000011011111111001110001110001111111000 1111111100001110100001111111000000000000000111100000 ',
  87. ' 9 ' = ' 0000111111000000000000011111111100000011000011111111100000011000111000001110000001101110000000111000001101100000000011000 0011011000000000110000011011000000000110000011011000000000110000110011100000001100001110001111100011100111100000111111111 1111111000000111111111111000000000000111111110000000 ',
  88. );
  89. $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
  90. for ($i = 0; $i < $i + +)
  91. Unset ($arr [$i]);//The first 10 lines are blank
  92. $y = 0;//with a top-to-bottom, left-to-right sequential read signature, starting at line No. 0 (actually line 10th)
  93. $len = 31;//read one line more than 20 lines in JQ, and J after a few lines occupy the position of the last character
  94. $code = Array ();//separated character signatures
  95. $str = ";
  96. while ($y < count ($arr [10])) {
  97. $flag = true;//Full 0 is a blank vertical line
  98. $line = ";
  99. for ($i = ten; $i < $len; $i + +) {
  100. if ($arr [$i] [$y])
  101. $flag = false;
  102. $line. = $arr [$i] [$y];
  103. }
  104. $ISW = false;
  105. $isy = false;
  106. Special handling of VW
  107. if ($str = = = $char [' V '] | | $str = = = = $char [' W ']) {
  108. $flag = true;
  109. $ISW = true;
  110. }elseif ($str = = = $char [' Y '] | | $str = = = $char [' A ']) {
  111. $isy = true;
  112. $flag = true;
  113. }
  114. if ($flag) {
  115. if (strlen ($STR) > 21)
  116. $code [] = $STR;
  117. $str = ";
  118. }else{
  119. $str. = $line;
  120. }
  121. if ($ISW) {
  122. $str = ' xx '. substr ($line, 2,strlen ($line));
  123. if ($str = = = ' 000000000000000000000 ')
  124. $str = ";
  125. $ISW = false;
  126. }
  127. if ($isy) {
  128. $str = $line;
  129. if ($str = = = ' 000000000000000000000 ')
  130. $str = ";
  131. $isy = false;
  132. }
  133. $y + +;
  134. }
  135. Output character
  136. foreach ($code as $v) {
  137. $match = false;
  138. foreach ($char as $key = + $v 2) {
  139. if ($v = = = $v 2) {
  140. Echo $key;
  141. $match = true;
  142. }
  143. }
  144. if (! $match)
  145. echo '? '; /no match to the character output question mark
  146. }
Copy Code
  • 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.