PageRenderTime 58ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/sabre/sabre_captcha.php

https://bitbucket.org/MaheshDhaduk/androidmobiles
PHP | 153 lines | 101 code | 19 blank | 33 comment | 13 complexity | d38168a9ec39b627f2987ecbba3759ee MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /*
  3. QuickCaptcha 1.0 - A bot-thwarting text-in-image web tool.
  4. Copyright (c) 2006 Web 1 Marketing, Inc.
  5. */
  6. /*
  7. Description : A function with a very simple but powerful xor method to encrypt
  8. and/or decrypt a string with an unknown key. Implicitly the key is
  9. defined by the string itself in a character by character way.
  10. There are 4 items to compose the unknown key for the character
  11. in the algorithm
  12. 1.- The ascii code of every character of the string itself
  13. 2.- The position in the string of the character to encrypt
  14. 3.- The length of the string that include the character
  15. 4.- Any special formula added by the programmer to the algorithm
  16. to calculate the key to use
  17. */
  18. FUNCTION Encrypt_Decrypt($Str_Message) {
  19. //Function : encrypt/decrypt a string message v.1.0 without a known key
  20. //Author : Aitor Solozabal Merino (spain)
  21. //Email : aitor-3@euskalnet.net
  22. //Date : 01-04-2005
  23. $Len_Str_Message=STRLEN($Str_Message);
  24. $Str_Encrypted_Message="";
  25. FOR ($Position = 0;$Position<$Len_Str_Message;$Position++){
  26. // long code of the function to explain the algoritm
  27. //this function can be tailored by the programmer modifyng the formula
  28. //to calculate the key to use for every character in the string.
  29. $Key_To_Use = (($Len_Str_Message+$Position)+1); // (+5 or *3 or ^2)
  30. //after that we need a module division because canĀ“t be greater than 255
  31. $Key_To_Use = (255+$Key_To_Use) % 255;
  32. $Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1);
  33. $Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted);
  34. $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use; //xor operation
  35. $Encrypted_Byte = CHR($Xored_Byte);
  36. $Str_Encrypted_Message .= $Encrypted_Byte;
  37. //short code of the function once explained
  38. //$str_encrypted_message .= chr((ord(substr($str_message, $position, 1))) ^ ((255+(($len_str_message+$position)+1)) % 255));
  39. }
  40. RETURN $Str_Encrypted_Message;
  41. } //end function
  42. $cnum = Encrypt_Decrypt(base64_decode($_GET['sabre_id']));
  43. $acceptedChars = $_GET['acceptedChars'];
  44. $stringlength = $_GET['stringlength'];
  45. $contrast = $_GET['contrast'];
  46. $num_polygons = $_GET['num_polygons']; // Number of triangles to draw. 0 = none
  47. $num_ellipses = $_GET['num_ellipses']; // Number of ellipses to draw. 0 = none
  48. $num_lines = $_GET['num_lines']; // Number of lines to draw. 0 = none
  49. $num_dots = $_GET['num_dots']; // Number of dots to draw. 0 = none
  50. $min_thickness = $_GET['min_thickness']; // Minimum thickness in pixels of lines
  51. $max_thickness = $_GET['max_thickness']; // Maximum thickness in pixles of lines
  52. $min_radius = $_GET['min_radius']; // Minimum radius in pixels of ellipses
  53. $max_radius = $_GET['max_radius']; // Maximum radius in pixels of ellipses
  54. $object_alpha = $_GET['object_alpha']; // How opaque should the obscuring objects be. 0 is opaque, 127 is transparent.
  55. $white_bg = $_GET['white_bg']; // White background. false = black, true = white
  56. /*------------------------------------------------*/
  57. $min_thickness = max(1,$min_thickness);
  58. $max_thickness = min(20,$max_thickness);
  59. $min_radius *= 3;// Make radii into height/width
  60. $max_radius *= 3;// Make radii into height/width
  61. $contrast = 255 * ($contrast / 100.0);
  62. $o_contrast = 1.3 * $contrast;
  63. $width = 20 * imagefontwidth (5);
  64. $height = 4 * imagefontheight (5);
  65. $image = imagecreatetruecolor ($width, $height);
  66. imagealphablending($image, true);
  67. if ($white_bg == 'true') {
  68. $white = imagecolorallocatealpha($image,255,255,255,0);
  69. imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $white);
  70. } else $black = imagecolorallocatealpha($image,0,0,0,0);
  71. $rotated = imagecreatetruecolor (70, 70);
  72. $x = 0;
  73. for ($i = 0; $i < $stringlength; $i++) {
  74. $buffer = imagecreatetruecolor (20, 20);
  75. $buffer2 = imagecreatetruecolor (40, 40);
  76. // Get a random color
  77. $red = mt_rand(0,255);
  78. $green = mt_rand(0,255);
  79. $blue = 255 - sqrt($red * $red + $green * $green);
  80. $color = imagecolorallocate ($buffer, $red, $green, $blue);
  81. // Create character
  82. imagestring($buffer, 5, 0, 0, $cnum{$i}, $color);
  83. // Resize character
  84. imagecopyresized ($buffer2, $buffer, 0, 0, 0, 0, 25 + mt_rand(0,12), 25 + mt_rand(0,12), 20, 20);
  85. // Rotate characters a little
  86. if (function_exists('imagerotate'))
  87. $rotated = imagerotate($buffer2, mt_rand(-25, 25),imagecolorallocatealpha($buffer2,0,0,0,0));
  88. else
  89. imagecopymerge ($rotated, $buffer2, 15, 15, 0, 0, 40, 40, 100);
  90. imagecolortransparent ($rotated, imagecolorallocatealpha($rotated,0,0,0,0));
  91. // Move characters around a little
  92. $y = mt_rand(1, 3);
  93. $x += mt_rand(2, 6);
  94. imagecopymerge ($image, $rotated, $x, $y, 0, 0, 40, 40, 100);
  95. $x += 22;
  96. imagedestroy ($buffer);
  97. imagedestroy ($buffer2);
  98. }
  99. imagedestroy ($rotated);
  100. if ($num_polygons > 0) for ($i = 0; $i < $num_polygons; $i++) {
  101. $vertices = array (
  102. mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
  103. mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
  104. mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25)
  105. );
  106. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
  107. imagefilledpolygon($image, $vertices, 3, $color);
  108. }
  109. if ($num_ellipses > 0) for ($i = 0; $i < $num_ellipses; $i++) {
  110. $x1 = mt_rand(0,$width);
  111. $y1 = mt_rand(0,$height);
  112. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
  113. // $color = imagecolorallocate($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast));
  114. imagefilledellipse($image, $x1, $y1, mt_rand($min_radius,$max_radius), mt_rand($min_radius,$max_radius), $color);
  115. }
  116. if ($num_lines > 0) for ($i = 0; $i < $num_lines; $i++) {
  117. $x1 = mt_rand(-$width*0.25,$width*1.25);
  118. $y1 = mt_rand(-$height*0.25,$height*1.25);
  119. $x2 = mt_rand(-$width*0.25,$width*1.25);
  120. $y2 = mt_rand(-$height*0.25,$height*1.25);
  121. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
  122. imagesetthickness ($image, mt_rand($min_thickness,$max_thickness));
  123. imageline($image, $x1, $y1, $x2, $y2 , $color);
  124. }
  125. if ($num_dots > 0) for ($i = 0; $i < $num_dots; $i++) {
  126. $x1 = mt_rand(0,$width);
  127. $y1 = mt_rand(0,$height);
  128. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast),$object_alpha);
  129. imagesetpixel($image, $x1, $y1, $color);
  130. }
  131. header('Content-type: image/png');
  132. imagepng($image);
  133. imagedestroy($image);
  134. ?>