Verification code cracking and anti-Cracking Ideas

Source: Internet
Author: User
Verification code cracking and anti-Cracking Ideas
Only one way to use php to crack the verification code is to collect the character pattern in the verification code and try to separate the characters in the verification code. What Artificial intelligence is obviously not feasible in php, so as long as the characters in the verification code can be collected and the characters in the verification code can be separated by a method, it can be cracked.
The idea of anti-cracking is mainly to use more characters in these two steps, such as Chinese characters, more fonts and variants, so that the same character has multiple signatures, or there is no fixed signature. The difficulty of separating characters is increased. characters in the verification code are not fixed in position, the size is not fixed, and the spacing is not fixed. Interference pixels must play a role.
The following uses a website verification code as an example to explain how to crack the verification code through the above two steps.
Note: some codes are from phper "Ba". thank you very much!

  1. /* Sort the numeric values and find the second element, because the first element is the background color and the second element is the character color. In other words, if each character uses a different color, or the background color is not so monotonous. how can I separate 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 verification code Image, read the pixel RGB into a two-dimensional array, and then extract 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 pixel color of the midline. The midline must be cut to characters...
  17. $ Colors [] = $ color;
  18. }
  19. $ MainColor = getMostRepeated ($ colors); // separate 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 image is in italic text. it is useless to convert characters into positive ones to facilitate character segmentation...
  26. If ($ y <16 ){
  27. $ Pos = 0;
  28. } Elseif ($ y >=16 & $ y <= 20 ){
  29. $ Pos = 1;
  30. $ Pic [$ y] [0] = 0;
  31. } Elseif ($ y >=21 & $ 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 color of the interference pixel is completely different from that of the character, it is easy to separate the character color and set the character pixel to 1. Therefore, the color of the interference pixel must be at least the same as that of the character!
  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
  50. $ Char = array (
  51. 'A' => '2017 0000000000000000000100000000000000000101100000000000000011111000000000000000111010000000000000111110000000000000011111100000000 0000101110011000000000011111000011000000000111010000011000000011110000000011000000011111100000011000000011111111100011000000000 0011111110110000000000000111111110000000000000000111111110000000000000001111111000000000000000011111110000000000000000001110000 000000000000000110 ',
  52. 'B' => '2017 1111111111111111111101111111111111111111101111111111111111111101100000001100000001101100000001100000001101100000001100000001101 ',
  53. 'C' => '2017 0000010111100000000000000111111111111100000001111111111111100000011101000011111110000111000000000000111000110000000000000011000 1100000000000000111011000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011 0000000000000000110110000000000000001100011000000000000001100011000000000000011000 ',
  54. 'D' => '2017 1111111111111111111101111111111111111111101111111111111111111101100000000000000001101100000000000000001101100000000000000001101 1000000000000000011011000000000000000011011000000000000000011011000000000000000011011100000000000000111001100000000000001110001 1110000000000111100001111000000001111000000111111111111111000000011111111111100000000000111111110000000 ',
  55. 'E' => '2017 1111111111111111111101111111111111111111101111111111111111111101100000001100000001101100000001100000001101100000001100000001101 ',
  56. 'F' => '2017 1111111111111111111101111111111111111111101111111111111111111101100000001100000000001100000001100000000001100000001100000000001 ',
  57. 'G' => '2017 0000010111100000000000000111111111111100000001111111111111100000011101000011111110000111000000000000111000110000000000000011000 1100000000000000111011000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011 ',
  58. 'H' => '2017 1111111111111111111101111111111111111111101111111111111111111100000000001100000000000000000001100000000000000000001100000000000 0000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000 ',
  59. 'I => '123 ',
  60. 'J' => '123 ',
  61. 'K' => '2017 1111111111111111111101111111111111111111101111111111111111111100000000001100000000000000000011100000000000000000110110000000000 0000111100111000000000001111000111100000000011110000011110000000111000000000111000001110000000000011100011100000000000001110011 0000000000000001110100000000000000000110000000000000000000010 ',
  62. 'L' => '2017 1111111111111111111101111111111111111111101111111111111111111100000000000000000001100000000000000000001100000000000000000001100 ',
  63. 'M' => '2017 1111111111111111111101111111111111111111101111110000000000000001111111000000000000000001111111100000000000000001111110000000000 0000001111111110000000000000000111111000000000000000011111110000000000000000011110000000000000001111110000000000001011100000000 0000001111100000000000011111101000000000000111110000000000000011100000000000000000111111111111111111110111111111111111111110111 ',
  64. 'N' => '2014, 1111111111111111111101111111111111111111101111100000000000000000111110000000000000000001111000000000000000000011100000000000000, 0000011110000000000000000001111000000000000000000011100000000000000000000111000000000000000000111110000000000000000011111000000 0000000000001111000000000000000000011110111111111111111111110111111111111111111110 ',
  65. 'O' => '2017 0000010111100000000000000111111111111000000001111111111111100000011101000000111110000111000000000000111000110000000000000011000 1100000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011000000000000000011011 1000000000000000110011000000000000011100011110000000000111100001111000000001111000000111111111111111000000001111111111100000000 ',
  66. 'P' => '2017 1111111111111111111101111111111111111111101111111111111111111101100000000110000000001100000000110000000001100000000110000000001 ',
  67. 'Q' => '2017 0000010111100000000000000111111111111000000001111111111111100000011101000011111110000111000000000000111000110000000000000011000 1000000000000000111011000000000000000011011000000000000000011011000000000000000011011000000000000000011011000000000000000011011 1000000000000000111011000000000000011111011110000000000111101001111000000001111001000111111111111110000000001111111111000000000 000111111110000000 ',
  68. 'R' => '2017 1111111111111111111101111111111111111111101111111111111111111101100000001100000000001100000001100000000001100000001100000000001 1000000011000000000011000000111110000000011100101110111100000011111111100111111000001111111100001111000000111011000000011110000 ',
  69. 'S '=> '2017 0001110000000000010000011111100000000011000111111110000000011000110001111000000001101100000111100000001101100000011100000001101 ',
  70. 'T' => '2017 1100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001 1000000000000000000011111111111111111111011111111111111111111011111111111111111111011000000000000000000011000000000000000000011 0000000000000000000110000000000000000000110000000000000000000110000000000000000000110000000000000000000 ',
  71. 'T' => '2014, 1100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001100000000000000000001, 1111111111111111111011111111111111111111011111111111111111111011000000000000000000011000000000000000000011000000000000000000011 0000000000000000000110000000000000000000110000000000000000000110000000000000000000 '. // When vt is enabled, a column is occupied on the left of T.
  72. 'U' => '2017 1111111111111111100001111111111111111100001111111111111111111000000000000000000011000000000000000000011100000000000000000001100 0000000000000000011000000000000000000011000000000000000000011000000000000000000011000000000000000000110000000000000000011110011 ',
  73. 'V' => '2017 1111000000000000000001111110000000000000001111111110000000000000000011111100000000000000001111111000000000000000001111111100000 0000000000111111100000000000000000111111000000000000000001111000000000000000111111000000000001011110100000000000011111000000000 0001011111000000000000111111000000000000001110100000000000000111100000000000000000 ', // read a column less
  74. 'W' => '2017 1111110000000000000001111111110000000000001111111111100000000000000001111111111100000000000011111111100000000000000011111111100 0000000000000011111000000000000001111111000000000111111100100000001111111110000000001111111000000000000011111100000000000000011 1111000000000000000111111111110000000000000000111111111110000000000011111111111000000000000001111111110000000000000000111110000 000000000011111110000000001111111001000000011111111100000000001111111000000000000111110100000000000000 ',
  75. 'X' => '2017 0000000000000000000101100000000000000001101111000000000000111001111110000000001110000011110000000011000000000111100000110000000 0000011111011000000000000011111110000000000000000111100000000000000000111110000000000000111100111100000000001111000111111000000 0111100000011110000001110000000000111100011100000000000001110110000000000000001110100000000000000000010 ',
  76. 'Y' => '2017 1100000000000000000001111000000000000000001111110000000000000000011110000000000000000000111110000000000000000001111100000000000 0000011111111111111000000000011111111111000000000111111111111000000001110000000000000000111100000000000000011110000000000000000 1110000000000000000011100000000000000000110000000000000000000100000000000000000000 ',
  77. 'Z' => '2017 0000000000000000001101100000000000000111101100000000000011111101100000000000111111101100000000001111001101100000000111100001101 1000000011110000011011000001111100000011011000111110000000011011001111100000000011011011110000000000011011111000000000000011011 ',
  78. '0' => '2014 0000010111101000000000001111111111111100000011111111011111100000111000000000000111000110000000000000011001100000000000000011101 1000000000000000011011000000000000000011011000000000000000011011100000000000001110001111100000000011110000111111111011111100000 0011111111111100000000000111111110000000 ',
  79. '1' => '2017 0011000000000000001100011000000000000001100110000000000000001100110000000000000001100111111111111111111100111111111111111111101 ',
  80. '2' => '2017 0000000000000000001100011000000000001111100110000000000001111100110000000000011011101100000000000110001101100000000001110001101 1000000000111000011011000000001110000011011100000011100000011011110000111100000011001111111110000000011000111111100000000011000 0111110000000000110 ',
  81. '3' => '2017 0110000000000000011000100000000000000011001100000001100000001101100000001100000001101100000001100000001101100000001100000001101 ',
  82. '4' => '2017 0000000000001100000000000000000111100000000000000001111100000000000000011001100000000000011110001100000000000111100001100000000 0011110000011000000000111000000011000000001110000000011000000011111111111111111111011111111111111111111011111111111111111111000 ',
  83. '5' => '2017 1111111110000000011001111111110000000011101100000110000000001101100000110000000001101100000110000000001101100000110000000001101 ',
  84. '6' => '2017 0000010111101110000000000111111111111100000011111111111111110000011101001010000111000110000011000000011000110000010000000011101 1000001100000000011011000001100000000011011000001100000000011011000001110000000011011000001111000001110011100000111111111110001 ',
  85. '7' => '2017 1100000000000000000001100000000000000000101100000000000001111101100000000000111111101100000000001111111001100000000111110000001 1000000111110000000011000001110100000000011000111100000000000011011111000000000000011111000000000000000011110000000000000000011 ',
  86. '8' => '2017 0000000000000111100000001110000001111110000011111100111111111000111111111111000011000110001111110000011101100000111000000001101 1000001111000000011011000000111000000011011000000111100000011011100101111100000011011111111001110001110001111111000111111110000 ',
  87. '9' => '2017 0000111111000000000000011111111100000011000011111111100000011000111000001110000001101110000000111000001101100000000011000001101 1000000000110000011011000000000110000011011000000000110000110011100000001100001110001111100011100111100000111111111111111100000 ',
  88. );
  89. $ Arr = fixImg ("https: // xxxxxxxxxx"); // Oh, the domain name and verification code address of a community are hidden here. to support https, openssl must be enabled in your php environment.
  90. For ($ I = 0; $ I <10; $ I ++)
  91. Unset ($ arr [$ I]); // The first 10 rows are blank.
  92. $ Y = 0; // read the pattern from top to bottom, left to right, starting from 0th rows (actually 10th rows)
  93. $ Len = 31; // read more than one row. JQ contains more than 20 rows, and the number of lines after J occupies the position of the previous character.
  94. $ Code = array (); // separated character pattern
  95. $ Str = '';
  96. While ($ y <count ($ arr [10]) {
  97. $ Flag = true; // all 0 are blank vertical bars
  98. $ Line = '';
  99. For ($ I = 10; $ 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 vw handling
  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 = '00'. substr ($ line, 2, strlen ($ line ));
  123. If ($ str = '20140901 ')
  124. $ Str = '';
  125. $ Isw = false;
  126. }
  127. If ($ isy ){
  128. $ Str = $ line;
  129. If ($ str = '20140901 ')
  130. $ Str = '';
  131. $ Isy = false;
  132. }
  133. $ Y ++;
  134. }
  135. // Output characters
  136. Foreach ($ code as $ v ){
  137. $ Match = false;
  138. Foreach ($ char as $ key => $ v2 ){
  139. If ($ v ===$ v2 ){
  140. Echo $ key;
  141. $ Match = true;
  142. }
  143. }
  144. If (! $ Match)
  145. Echo '? '; // The question mark of the character output that does not match
  146. }

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.