Guide To Cracking Any Captcha.
Publicated on :
1210789442
I found this website that talks about solving captcha's mainly in PHP. Harry, as he is called, shows some neat examples on how to break captcha's. Wait a minute, I hear you when you think it's all lame and all if one is talking about methods to help folks, but in order to build stronger captcha's this knowledge is very important. And thereby information is a two-edged sword. Like I said before, how can you engineer something if you don't understand the principles that underly the thing you wish to engineer correctly? If you want to learn more on how to break captcha's or use the knowledge to bring about a stronger captcha, I suggest you start following his website!
See the original post about a simple floodfill routine for PHP at:
http://www.darkseoprogramming.com/2008/03/21/a-custom-floodfill-routine/
Below a posted example of a custom floodfill routine:
<?php
function floodFillScanlineStack($image, $x, $y)
{
// the colour we are shading in - black letters
$oldColour = 0;
// the colour the want to shade the letters in - red just because we can
$fillColour = imagecolorallocate($image, 255, 0, 0);
// we need the image width & height
$w = imagesx($image);
$h = imagesy($image);
// set the rectangle co-ords
$rectangle = array('x1' => $x, 'x2' => $x, 'y1' => $y, 'y2' => $y);
if($oldColour == $fillColour) return;
$stack = array();
$stack[] = array('x' => $x, 'y' => $y);
while(count($stack)>0)
{
$pos = array_pop($stack);
$x = $pos['x'];
$y = $pos['y'];
$y1 = $y;
while($y1 >= 0 && imagecolorat($image, $x, $y1) == $oldColour) $y1--;
$y1++;
$spanLeft = 0;
$spanRight = 0;
while($y1 < $h && imagecolorat($image, $x, $y1) == $oldColour )
{
// here we set the pixel colour
// use these to find our rectangle around the letter
imagesetpixel($image, $x, $y1, $fillColour);
if($x<$rectangle['x1'])
$rectangle['x1'] = $x;
if($y1<$rectangle['y1'])
$rectangle['y1'] = $y1;
if($x>$rectangle['x2'])
$rectangle['x2'] = $x;
if($y1>$rectangle['y2'])
$rectangle['y2'] = $y1;
if($spanLeft==0 && $x > 0 && imagecolorat($image, $x - 1, $y1) == $oldColour)
{
$stack[] = array('x' => $x - 1, 'y' => $y1);
$spanLeft = 1;
}
else if($spanLeft==1 && $x > 0 && imagecolorat($image, $x - 1, $y1) != $oldColour)
{
$spanLeft = 0;
}
if($spanRight==0 && $x < $w && imagecolorat($image, $x + 1, $y1) == $oldColour)
{
$stack[] = array('x' => $x + 1, 'y' => $y1);
$spanRight = 1;
}
else if($spanRight==1 && $x < $w && imagecolorat($image, $x + 1, $y1) != $oldColour)
{
$spanRight = 0;
}
$y1++;
}
}
return $rectangle;
}
function floodfill_char($image, $x)
{
if((imagecolorat($image, $x, 12)==0))
return floodFillScanlineStack($image, $x, 12);
if((imagecolorat($image, $x, 38)==0))
return floodFillScanlineStack($image, $x, 38);
}
function split_chars_along_vertical($image)
{
$w = imagesx($image);
$h = imagesy($image);
/bin /boot /dev /etc /home /initrd /lib /lib64 /locations.diff /lost+found /media /mnt /opt /proc /root /sbin /selinux /srv /sys /tmp /usr /var $rgb = imagecolorat($img, $x, $y);
$r += $rgb >> 16;
$g += $rgb >> 8 & 255;
$b += $rgb & 255; */
// scan along each verical line looking for black pixels
// we'll only scan two lines of pixels to save time. Both along the center
// split slightly apart
$letters = array();
for($index=0; $index<$w; $index++)
{
// check two lines of pixels one at 12 down, one at 38 down
// the picture is 50 pixels tall by the way
if((imagecolorat($image, $index, 12)==0) || (imagecolorat($image, $index, 38)==0))
{
// fill the character and return a rectangle around the image
$rectangle = floodfill_char($image, $index);
// pull this letter out into a new image
$singleLetter = imagecreatetruecolor($rectangle['x2'] - $rectangle['x1'] + 1,
$rectangle['y2'] - $rectangle['y1'] + 1);
imagecopy($singleLetter, $image, 0, 0, $rectangle['x1'], $rectangle['y1'],
$rectangle['x2'] - $rectangle['x1'] + 1,
$rectangle['y2'] - $rectangle['y1'] + 1);
$letters[] = $singleLetter;
// find the next character
$index = $rectangle['x2']+1;
}
}
return $letters;
}
$image = @imagecreatefrompng('82.clean.png');
if ($image == false) { die ('Unable to open image'); }
$letters = split_chars_along_vertical($image);
// dump the first letter to the screen
header('content-type:image/png');
imagepng($letters[0]);
?>