forked from v1ra1/Captcha2Text
/
hasherv2.php
201 lines (156 loc) · 10.4 KB
/
hasherv2.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/*
PHP Captcha Solver Copyright (C) 2011 Karthik A
This program comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions.
*/
global $letterlist;
//The letter database
$letterlist = array(
array('id' => '3','letter' => 'x','hash' => '000000001000001000000000000110001100000000000001101100000000000000011100000000000000001110000000000000001101100000000000001100011000000000000100000100001'),
array('id' => '4','letter' => 'y','hash' => '000000001111100100000000000111111001000000000000000110100000000000000001010000000000000000101000000000000000100100000000001111111110000000000111111110001'),
array('id' => '5','letter' => 'c','hash' => '000000000011100000000000000011111000000000000011000110000000000001000001000000000000100000100000000000010000010000000000001100011000000000000010001000001'),
array('id' => '6','letter' => '9','hash' => '000000011000000000000000011110011000000000011001100110000000001000010001000000000100001000100000000011001000110000000000111111110000000000001111110000001'),
array('id' => '7','letter' => 'm','hash' => '000000001111111000000000000011111100000000000010000000000000000001111111000000000000011111100000000000010000000000000000001111111000000000000011111100001'),
array('id' => '8','letter' => '8','hash' => '000000010001100000000000011101111000000000011011100110000000001000100001000000000100010000100000000011011100110000000000111011110000000000001000110000001'),
array('id' => '9','letter' => 'p','hash' => '000000001111111110000000000111111111000000000001000100000000000001000001000000000000100000100000000000011000110000000000000111110000000000000001110000001'),
array('id' => '10','letter' => 'i','hash' => '0000000000000010000000000001000001000000000110111111100000000011011111110000000000000000001000000000000000000100001'),
array('id' => '11','letter' => 'u','hash' => '000000001111100000000000000111111000000000000000000110000000000000000001000000000000000000100000000000000000100000000000001111111000000000000111111100001'),
array('id' => '12','letter' => 'q','hash' => '000000000011100000000000000011111000000000000011000110000000000001000001000000000000100000100000000000001000100000000000001111111110000000000111111111001'),
array('id' => '13','letter' => 'd','hash' => '000000000011100000000000000011111000000000000011000110000000000001000001000000000000100000100000000000001000100000000001111111111000000000111111111100001'),
array('id' => '15','letter' => 'g','hash' => '000000000111010100000000000111111111000000000010001010100000000001000101010000000000100010101000000000011111010100000000000111001110000000000110000010001'),
array('id' => '16','letter' => 'o','hash' => '000000000011100000000000000011111000000000000011000110000000000001000001000000000000100000100000000000011000110000000000000111110000000000000001110000001'),
array('id' => '17','letter' => '2','hash' => '000000010000001000000000011000001100000000011000001110000000001000001101000000000100001100100000000011001100010000000000111100001000000000001100000100001'),
array('id' => '18','letter' => '7','hash' => '000001000000011000000000100000011100000000010000011000000000001000011000000000000100011000000000000010011000000000000001111000000000000000111000000000001'),
array('id' => '19','letter' => 'n','hash' => '000000001111111000000000000111111100000000000001000000000000000001000000000000000000100000000000000000011000000000000000000111111000000000000001111100001'),
array('id' => '20','letter' => 'b','hash' => '000001111111111000000000111111111100000000000001000100000000000001000001000000000000100000100000000000011000110000000000000111110000000000000001110000001'),
array('id' => '21','letter' => 'h','hash' => '000001111111111000000000111111111100000000000001000000000000000001000000000000000000100000000000000000011000000000000000000111111000000000000001111100001'),
array('id' => '22','letter' => 't','hash' => '000000001000000000000000000100000000000000001111111100000000000111111111000000000000100000100000000000010000010000000000000000011000000000000000001000001'),
array('id' => '26','letter' => 'r','hash' => '000000001000000000000000000111111100000000000001111110000000000001100000000000000000100000000000000000010000000000000000001100000000000000000010000000001'),
array('id' => '24','letter' => 'e','hash' => '000000000011100000000000000011111000000000000011010110000000000001001001000000000000100100100000000000011010010000000000000111011000000000000001101000001'),
array('id' => '25','letter' => 'f','hash' => '000000000010000000000000000001000000000000001111111110000000001111111111000000000100001000000000000010000100000000000001110000000000000000011000000000001'),
array('id' => '27','letter' => 'a','hash' => '000000000000110000000000000010111100000000000011010010000000000001001001000000000000100100100000000000010010100000000000001111111000000000000011111100001'),
array('id' => '28','letter' => 'v','hash' => '000000001100000000000000000111100000000000000000111100000000000000000111000000000000000011100000000000000111100000000000001111000000000000000110000000001'),
array('id' => '29','letter' => 'k','hash' => '00000111111111100000000011111111110000000000000011000000000000000011110000000000000011001100000000000001000011000000000000000000100001'),
array('id' => '30','letter' => '6','hash' => '000000011111100000000000011111111000000000011000100110000000001000100001000000000100010000100000000011001100110000000000110011110000000000000000110000001'),
array('id' => '31','letter' => 'j','hash' => '00000000000000110000000000000000011100000000000000000010000000000000000001000000000010000000100000001101111111110000000110111111110001'),
array('id' => '32','letter' => '5','hash' => '000001111100100000000000111110011000000000010001000110000000001001000001000000000100100000100000000010011000110000000001000111110000000000000001110000001'),
array('id' => '33','letter' => 'w','hash' => '000000001111110000000000000111111100000000000000000110000000000000011110000000000000001111000000000000000000110000000000001111111000000000000111111000001'),
array('id' => '34','letter' => 'z','hash' => '0000000010000110000000000001000111000000000000100110100000000000010110010000000000001110001000000000000110000100001'),
array('id' => '35','letter' => 's','hash' => '000000000110010000000000000111101100000000000010010010000000000001001001000000000000100100100000000000010010010000000000001101111000000000000010011000001'),
array('id' => '36','letter' => '3','hash' => '000000100000010000000000110000001100000000010000000010000000001000100001000000000100010000100000000011011100110000000000111011110000000000001000110000001'),
array('id' => '37','letter' => '4','hash' => '000000000011000000000000000011100000000000000011010000000000000011001000000000000011000100000000000011111111110000000001111111111000000000000000100000001')
);
require 'class.cropcanvas.php';
$cc = new canvasCrop();
$src = imagecreatefromJPEG('captcha.jpg') or die('Problem with source');
$out = ImageCreateTrueColor(imagesx($src),imagesy($src)) or die('Problem In Creating image');
// scan image pixels
for ($x = 0; $x < imagesx($src); $x++) {
for ($y = 0; $y < imagesy($src); $y++) {
$src_pix = imagecolorat($src,$x,$y);
$src_pix_array = rgb_to_array($src_pix);
if ($src_pix_array[0] > 100 && $src_pix_array[1] >100 && $src_pix_array[2] > 100) {
$src_pix_array[0] = 255;
$src_pix_array[1] = 255;
$src_pix_array[2] = 255;
}
else{
$src_pix_array[0] = 0;
$src_pix_array[1] = 0;
$src_pix_array[2] = 0;
}
imagesetpixel($out, $x, $y, imagecolorallocate($out, $src_pix_array[0], $src_pix_array[1], $src_pix_array[2]));
}
}
for($fx = 0; $fx <60 ;$fx++){
imagesetpixel($out, $fx, 0, imagecolorallocate($out, 255, 255, 255));
}
for($fy = 0; $fy < 20;$fy++){
imagesetpixel($out, 59, $fy, imagecolorallocate($out, 255, 255, 255));
}
for($fx = 0; $fx <60 ;$fx++){
imagesetpixel($out, $fx, 19, imagecolorallocate($out, 255, 255, 255));
}
for($fy = 0;$fy < 20;$fy++){
imagesetpixel($out, 0, $fy, imagecolorallocate($out, 255, 255, 255));
}
// write $out to disc
imagejpeg($out, 'output.jpg',100) or die('Problem saving output image');
imagedestroy($out);
$src = imagecreatefromJPEG('output.jpg') or die('Problem with source');
$out = ImageCreateTrueColor(imagesx($src),imagesy($src)) or die('Problem In Creating image');
// scan image pixels
$ino = 0;
$started = 0;
for ($x = 0; $x < imagesx($src); $x++) {
for ($y = 0; $y < imagesy($src); $y++) {
$src_pix = imagecolorat($src,$x,$y);
$src_pix_array = rgb_to_array($src_pix);
if ($src_pix_array[0] < 100 && $src_pix_array[1] < 100 && $src_pix_array[2] < 100 && $started ==0) {
$csx = $x;
$csy = 0;
$started = 1;
$white = 0;
}
if ($src_pix_array[0] < 100 && $src_pix_array[1] < 100 && $src_pix_array[2] < 100 ) {
$white = 0;
}
if($started == 1 && $y == 19 && $white == 1 ){
$cey = 19;
$cex = $x;
$cc->loadImage('output.jpg');
$cc->cropToDimensions($csx, $csy, $cex, $cey);
$cc->saveImage('ltr'.$ino.'.jpg');
$ino++;
$started = 0;
$csx.",".$csy.",".$cex.",".$cey;
"<br />";
}
}
$white = 1;
}
$srr = '';
for($ino = 0;$ino < 6;$ino++){
$src = imagecreatefromJPEG('ltr'.$ino.'.jpg') or die('Problem with source');
$out = ImageCreateTrueColor(imagesx($src),imagesy($src)) or die('Problem In Creating image');
$string = '';
// scan image pixels
for ($x = 0; $x < imagesx($src); $x++) {
for ($y = 0; $y < imagesy($src); $y++) {
$src_pix = imagecolorat($src,$x,$y);
$src_pix_array = rgb_to_array($src_pix);
if ($src_pix_array[0] > 100 && $src_pix_array[1] >100 && $src_pix_array[2] > 100) {
$string .='0';
}
else{
$string .='1';
}
}
}
$string .='1';
//echo $string."<br />"; //Uncomment this when building database
for($i=0; $i<count($letterlist); $i++)
if(strcmp($letterlist[$i]['hash'],$string)==0)
{
$srr.=$letterlist[$i]['letter'];
break;
}
}
file_put_contents("res.txt",$srr);
echo $srr;
// split rgb to components
function rgb_to_array($rgb) {
$a[0] = ($rgb >> 16) & 0xFF;
$a[1] = ($rgb >> 8) & 0xFF;
$a[2] = $rgb & 0xFF;
return $a;
}
function hashToText($hash){
for($i=0; $i<count($letterlist); $i++)
if($letterlist[$i]['hash']===$hash)
return $letterlist[$i]['letter'];
return 'X';
}
?>