php破解图片验证码
PHP #破解验证码 #类2012-05-26 11:53
解决验证码的问题。
/**
* Author: zj mail:ggbox@163.com
* 2010/5/11
*/
class crackimg{
private $image=null;
private $size=0;
private $im=null;
private $width=0;
private $height=0;
private $char=array();
private $string=array();
public $code='';
//某具体验证码对应数字的2值码。
private $charCode=array(
'0'=>'1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,01,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0',
'1'=>'1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,01,0,0,0,0,0,0,0,0,0,01,0,0,0,0,0,0,0,0,0,0',
'2'=>'1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,01,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,01,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0',
'3'=>'1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,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this->im=imagecreatefrompng($this->image);
$this->width=$this->size[0];
$this->height=$this->size[1];
$this->imgToBinarray();
$this->imgToBinstring();
$this->getCode();
}
//图片对应数值的二值化数组。
private function imgToBinarray(){
for($x=1; $x < $this->width; $x ++){
$flag[$x]=false;
for($y=1; $y < $this->height; $y ++){
$color=imagecolorat($this->im,$x,$y);
if($color > 0 && $flag[$x] == false){
$flag[$x] = true;
}
if($flag[$x]==true){
$col[$x][] = $color;
}
}
}
$n=0;
foreach($col as $k => $v){
$tmparray[] = join(",",$v);
//垂直不重叠的情况下,分隔的字符必定存在空白
//如果存在干扰线,应该用定宽分隔比较好。
if(is_array($col[$k-1]) && !is_array($col[$k+1])){
$n++;
$this->char[$n]=$tmparray;
$tmparray=array();
}
}
}
//图片对应数值的二值化字符串。返回数组。
private function imgToBinstring(){
foreach($this->char as $key => $val){
foreach($val as $v){
$this->string[$key].=$v;
}
}
}
public function getBinarray(){
return $this->char ;
}
public function getBinstring(){
return $this->string;
}
//返回图片验证码数值
public function getCode(){
$precent=0;
foreach($this->string as $scode){
foreach($this->charCode as $code => $string){
//照某站图片验证,不存在干扰的话,相似比应该是100的。
similar_text($scode,$string,$precent);
if($precent > 99){
$precent=0;
$this->code.=$code;
}
}
}
}
public function display(){
//Header("Content-type: image/PNG");
echo "<img src='$this->image'></img>";
}
}
$image="http://www.xxx.com/common/imgcode.php";//目标站就隐藏了:)
//$image="test.png";
$png=new crackimg($image);
//$png->display();
//print_r($png->getBinstring());
print_r($png->code);相关文章
- PHP公历转农历(阳历转阴历)的类 2012/05/26
- PHP伪静态函数 2012/05/25
- PHP根据时间戳返回星期几的函数 2012/05/24
- PHP魔术常量 2012/05/24
- PHP手册中文翻译补完计划参与方式 2012/05/24
- PHP统计utf8中文字符个数 2012/05/24
- 出现Unable to find the socket transport 'ssl' 解决方法 2012/05/23
- jquery循环map/数组/对象的方法 2012/05/20
- Call to undefined function curl_init()错误的解决方法 2012/05/20
- PHP删除目录/文件夹的三种方法 2012/05/18