-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaptcha.php
123 lines (115 loc) · 8.51 KB
/
captcha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
define ('start_x', 6);
define ('word_h', 31);
function get_ans($url) {
$im = imagecreatefromjpeg($url);
imagegif($im, '0.gif');
$rgbArray = array();
$res = $im;
$size = getimagesize($url);
$wid = $size['0'];
$hid = $size['1'];
for ($i = 0; $i < $hid; ++ $i) {
for ($j = 0; $j < $wid; ++ $j) {
$rgb = imagecolorat($res, $j, $i);
$rgbArray[$i][$j] = imagecolorsforindex($res, $rgb);
}
}
for ($i = 0; $i < $hid; $i ++) {
for ($j = 0; $j < $wid; $j ++) {
if ($rgbArray[$i][$j]['blue'] < 212) {
echo '0';
} else {
echo '1';
}
}
echo "\n";
}
$data = array("", "", "", "");
$l = $wid;
$r = 0;
$cnt = 0;
$pre_is_word = 0;
for ($i = 0; $i < $wid; $i++) {
if ($cnt > 3) break;
$has_num = 0;
for ($j = start_x; $j < start_x + word_h; $j++) {
if ($rgbArray[$j][$i]['blue'] < 212) {
$l = min($l, $i);
$r = max($r, $i);
$has_num = 1;
$pre_is_word = 1;
break;
}
}
if ($has_num == 0 && $pre_is_word == 1) {
for ($x = start_x; $x < start_x + word_h; $x++) {
for ($y = $l; $y < $r + 1; $y++)
if ($rgbArray[$x][$y]['blue'] < 212) {
$data[$cnt] .= '0';
# echo '0';
}
else {
$data[$cnt] .= '1';
# echo '1';
}
#echo "\n";
}
$cnt = $cnt + 1;
$l = $wid;
$r = 0;
$pre_is_word = 0;
}
}
#for ($i = 0; $i < 4; $i++) echo $data[$i]."\n";
$Keys = array(
'0' => '1000000000000001000000000000000000000000000000000000000000000000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000000000000000000000000000000000000000000000001000000000000001',
'1' => '1100000110000011000001000000100000010000000000000000000000000001100000110000011000001100000110000011000001100000110000011000001100000110000011000001100000110000011000001100000110000011000001100000110000011000001100000',
'2' => '1000000000000001000000000000000000000000000000000000000000000000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000111111111100000011111111110000001111111110000001111111111000001111111111000000111111111000000111111111100000111111111100000011111111110000011111111110000001111111110000001111111111000001111111111000000111111111100000111111111100000111111111100000011111111110000011111111110000000000000000000000000000000000000000000000000000000000000000',
'3' => '1000000000000001000000000000000000000000000000000000000000000000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000111111111110000011111111100000001111111100000001111111000000011111111100000011111111110000000111111111110000000111111111100000001111111111000000111111111110000011111111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000000000000000000000000000000000000000000000001000000000000001',
'4' => '11111110000001111111111100000111111111111000001111111111100000011111111111000001111111111110000011111111111000000111111111110000011111111111000000111111111110000001111111111100000111111111110000001111111111100000010000011111000001100000111100000011000001111000000110000011110000011100000111000000111000001110000001110000011100000111100000110000001111000001100000000000000000000000000000000000000000000000000000000000000000000111111111100000111111111111000001111111111110000011111111111100000111111111111000001111111111110000011',
'5' => '0000000000000000000000000000000000000000000000000000000000000000000001111111111100000111111111110000011111111111000001111111111100000111111111110000011111111111000001111111111100000000000000010000000000000000000000000000000000000000000000001111111111100000111111111110000011111111111000001111111111100000111111111110000011111111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000000000000000000000000000000000000000000000001000000000000001',
'6' => '1000000000000001000000000000000000000000000000000000000000000000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111111111000001111111111100000111111111110000011111111111000000000000000100000000000000000000000000000000000000000000000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000000000000000000000000000000000000000000000001000000000000001',
'7' => '0000000000000000000000000000000000000000000000000000000000000000000001111110000000000111110000000000011111000001000001111100000111111111110000011111111110000001111111111000001111111111100000111111111110000011111111110000001111111111000001111111111100000111111111110000011111111110000001111111111000001111111111100000111111111110000011111111110000001111111111000001111111111100000111111111100000011111111110000001111111111000001111111111100000111111111100000011111111110000001111111111000001111111',
'8' => '1000000000000001000000000000000000000000000000000000000000000000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000011110000001000000000000001110000000000001111100000000001111100000000000011100000000000000100000001110000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000000000000000000000000000000000000000000000001000000000000001',
'9' => '1000000000000001000000000000000000000000000000000000000000000000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000011111100000000001111110000000000000000000000000000000000000000000000000000010000000000000001111111111100000111111111110000011111111111000001111111111100000000001111110000000000111111000000000011111100000000001111110000000000111111000000000000000000000000000000000000000000000000000001000000000000001',
'+' => '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000001111111111110000011111111111100000111111111111000001111111111110000011111111111100000111111000000000000000000000000000000000000000000000000000000000000000000001111110000011111111111100000111111111111000001111111111110000011111111111100000111111111111000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
'-' => '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
);
$oper = -1;
$a = 0;
$b = 0;
foreach($data as $numKey => $numString)
{
$max=0.0;
$num = 0;
foreach($Keys as $key => $value)
{
$percent=0.0;
similar_text($value, $numString,$percent);
if(intval($percent) > $max)
{
$max = $percent;
$num = $key;
if(intval($percent) > 95) {
if ('0' <= $key && $key <= '9') {
if ($oper == -1) {
$a = $a * 10 + intval($key - '0');
} else {
$b = $b * 10 + intval($key - '0');
}
} else if ($key == '-') {
$oper = 0;
} else {
$oper = 1;
}
break;
}
}
}
}
if ($oper == 0)
return $a - $b;
else
return $a + $b;
}