rucaptcha 2.5.4 → 2.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/rucaptcha/colors.h +265 -18
- data/ext/rucaptcha/rucaptcha.c +172 -111
- data/lib/rucaptcha/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9d3d4dbd1dc22a2d97ed2d3d1fcc248621bbc97a90e0823c024244de9493c57
|
4
|
+
data.tar.gz: 2d430de72e74176b92b021bf4f0462ba8f73ba147e3522c47f554ee8f72d3e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc1c19827b035d8e50e4ce9c42d39f4df4ceff1682b1eacc866d69d3c61b4bf723b51705e1eb275880aa8b7161c7baeff6ca591b509528899c1097bd66381c65
|
7
|
+
data.tar.gz: 0174b9a8e99f194d51fc69126f3fe1d38292b863db10fbbf8a76f2a1843ff23f882871613edc67c946c88a29cd26b9f37b3fd73b11457128cc1e6c371f234b29
|
data/CHANGELOG.md
CHANGED
data/ext/rucaptcha/colors.h
CHANGED
@@ -40,7 +40,45 @@ static char *colors[] = {
|
|
40
40
|
"\xD5\x00\x00"
|
41
41
|
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
42
42
|
|
43
|
-
//
|
43
|
+
// Red #B71C1C
|
44
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
45
|
+
"\xB7\x1C\x1C"
|
46
|
+
"\xB7\x1C\x1C"
|
47
|
+
"\xB7\x1C\x1C"
|
48
|
+
"\xB7\x1C\x1C"
|
49
|
+
"\xB7\x1C\x1C"
|
50
|
+
"\xB7\x1C\x1C"
|
51
|
+
"\xB7\x1C\x1C"
|
52
|
+
"\xB7\x1C\x1C"
|
53
|
+
"\xB7\x1C\x1C"
|
54
|
+
"\xB7\x1C\x1C"
|
55
|
+
"\xB7\x1C\x1C"
|
56
|
+
"\xB7\x1C\x1C"
|
57
|
+
"\xB7\x1C\x1C"
|
58
|
+
"\xB7\x1C\x1C"
|
59
|
+
"\xB7\x1C\x1C"
|
60
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
61
|
+
|
62
|
+
// Red #E53935
|
63
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
64
|
+
"\xE5\x39\x35"
|
65
|
+
"\xE5\x39\x35"
|
66
|
+
"\xE5\x39\x35"
|
67
|
+
"\xE5\x39\x35"
|
68
|
+
"\xE5\x39\x35"
|
69
|
+
"\xE5\x39\x35"
|
70
|
+
"\xE5\x39\x35"
|
71
|
+
"\xE5\x39\x35"
|
72
|
+
"\xE5\x39\x35"
|
73
|
+
"\xE5\x39\x35"
|
74
|
+
"\xE5\x39\x35"
|
75
|
+
"\xE5\x39\x35"
|
76
|
+
"\xE5\x39\x35"
|
77
|
+
"\xE5\x39\x35"
|
78
|
+
"\xE5\x39\x35"
|
79
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
80
|
+
|
81
|
+
// Orange A700 #DD2C00
|
44
82
|
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
45
83
|
"\xDD\x2C\x00"
|
46
84
|
"\xDD\x2C\x00"
|
@@ -59,7 +97,140 @@ static char *colors[] = {
|
|
59
97
|
"\xDD\x2C\x00"
|
60
98
|
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
61
99
|
|
62
|
-
//
|
100
|
+
// Orange #FF3D00
|
101
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
102
|
+
"\xFF\x3D\x00"
|
103
|
+
"\xFF\x3D\x00"
|
104
|
+
"\xFF\x3D\x00"
|
105
|
+
"\xFF\x3D\x00"
|
106
|
+
"\xFF\x3D\x00"
|
107
|
+
"\xFF\x3D\x00"
|
108
|
+
"\xFF\x3D\x00"
|
109
|
+
"\xFF\x3D\x00"
|
110
|
+
"\xFF\x3D\x00"
|
111
|
+
"\xFF\x3D\x00"
|
112
|
+
"\xFF\x3D\x00"
|
113
|
+
"\xFF\x3D\x00"
|
114
|
+
"\xFF\x3D\x00"
|
115
|
+
"\xFF\x3D\x00"
|
116
|
+
"\xFF\x3D\x00"
|
117
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
118
|
+
|
119
|
+
// Orange #BF360C
|
120
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
121
|
+
"\xBF\x36\x0C"
|
122
|
+
"\xBF\x36\x0C"
|
123
|
+
"\xBF\x36\x0C"
|
124
|
+
"\xBF\x36\x0C"
|
125
|
+
"\xBF\x36\x0C"
|
126
|
+
"\xBF\x36\x0C"
|
127
|
+
"\xBF\x36\x0C"
|
128
|
+
"\xBF\x36\x0C"
|
129
|
+
"\xBF\x36\x0C"
|
130
|
+
"\xBF\x36\x0C"
|
131
|
+
"\xBF\x36\x0C"
|
132
|
+
"\xBF\x36\x0C"
|
133
|
+
"\xBF\x36\x0C"
|
134
|
+
"\xBF\x36\x0C"
|
135
|
+
"\xBF\x36\x0C"
|
136
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
137
|
+
|
138
|
+
// Orange #FF6D00
|
139
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
140
|
+
"\xFF\x6D\x00"
|
141
|
+
"\xFF\x6D\x00"
|
142
|
+
"\xFF\x6D\x00"
|
143
|
+
"\xFF\x6D\x00"
|
144
|
+
"\xFF\x6D\x00"
|
145
|
+
"\xFF\x6D\x00"
|
146
|
+
"\xFF\x6D\x00"
|
147
|
+
"\xFF\x6D\x00"
|
148
|
+
"\xFF\x6D\x00"
|
149
|
+
"\xFF\x6D\x00"
|
150
|
+
"\xFF\x6D\x00"
|
151
|
+
"\xFF\x6D\x00"
|
152
|
+
"\xFF\x6D\x00"
|
153
|
+
"\xFF\x6D\x00"
|
154
|
+
"\xFF\x6D\x00"
|
155
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
156
|
+
|
157
|
+
// Green #00C853
|
158
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
159
|
+
"\x00\xC8\x53"
|
160
|
+
"\x00\xC8\x53"
|
161
|
+
"\x00\xC8\x53"
|
162
|
+
"\x00\xC8\x53"
|
163
|
+
"\x00\xC8\x53"
|
164
|
+
"\x00\xC8\x53"
|
165
|
+
"\x00\xC8\x53"
|
166
|
+
"\x00\xC8\x53"
|
167
|
+
"\x00\xC8\x53"
|
168
|
+
"\x00\xC8\x53"
|
169
|
+
"\x00\xC8\x53"
|
170
|
+
"\x00\xC8\x53"
|
171
|
+
"\x00\xC8\x53"
|
172
|
+
"\x00\xC8\x53"
|
173
|
+
"\x00\xC8\x53"
|
174
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
175
|
+
|
176
|
+
// Green #00C853
|
177
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
178
|
+
"\x00\xC8\x53"
|
179
|
+
"\x00\xC8\x53"
|
180
|
+
"\x00\xC8\x53"
|
181
|
+
"\x00\xC8\x53"
|
182
|
+
"\x00\xC8\x53"
|
183
|
+
"\x00\xC8\x53"
|
184
|
+
"\x00\xC8\x53"
|
185
|
+
"\x00\xC8\x53"
|
186
|
+
"\x00\xC8\x53"
|
187
|
+
"\x00\xC8\x53"
|
188
|
+
"\x00\xC8\x53"
|
189
|
+
"\x00\xC8\x53"
|
190
|
+
"\x00\xC8\x53"
|
191
|
+
"\x00\xC8\x53"
|
192
|
+
"\x00\xC8\x53"
|
193
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
194
|
+
|
195
|
+
// Green #64DD17
|
196
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
197
|
+
"\x64\xDD\x17"
|
198
|
+
"\x64\xDD\x17"
|
199
|
+
"\x64\xDD\x17"
|
200
|
+
"\x64\xDD\x17"
|
201
|
+
"\x64\xDD\x17"
|
202
|
+
"\x64\xDD\x17"
|
203
|
+
"\x64\xDD\x17"
|
204
|
+
"\x64\xDD\x17"
|
205
|
+
"\x64\xDD\x17"
|
206
|
+
"\x64\xDD\x17"
|
207
|
+
"\x64\xDD\x17"
|
208
|
+
"\x64\xDD\x17"
|
209
|
+
"\x64\xDD\x17"
|
210
|
+
"\x64\xDD\x17"
|
211
|
+
"\x64\xDD\x17"
|
212
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
213
|
+
|
214
|
+
// Blue #2E7D32
|
215
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
216
|
+
"\x2E\x7D\x32"
|
217
|
+
"\x2E\x7D\x32"
|
218
|
+
"\x2E\x7D\x32"
|
219
|
+
"\x2E\x7D\x32"
|
220
|
+
"\x2E\x7D\x32"
|
221
|
+
"\x2E\x7D\x32"
|
222
|
+
"\x2E\x7D\x32"
|
223
|
+
"\x2E\x7D\x32"
|
224
|
+
"\x2E\x7D\x32"
|
225
|
+
"\x2E\x7D\x32"
|
226
|
+
"\x2E\x7D\x32"
|
227
|
+
"\x2E\x7D\x32"
|
228
|
+
"\x2E\x7D\x32"
|
229
|
+
"\x2E\x7D\x32"
|
230
|
+
"\x2E\x7D\x32"
|
231
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
232
|
+
|
233
|
+
// Blue #2962FF
|
63
234
|
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
64
235
|
"\x29\x62\xFF"
|
65
236
|
"\x29\x62\xFF"
|
@@ -78,23 +249,61 @@ static char *colors[] = {
|
|
78
249
|
"\x29\x62\xFF"
|
79
250
|
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
80
251
|
|
81
|
-
//
|
252
|
+
// Blue #0D47A1
|
253
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
254
|
+
"\x0D\x47\xA1"
|
255
|
+
"\x0D\x47\xA1"
|
256
|
+
"\x0D\x47\xA1"
|
257
|
+
"\x0D\x47\xA1"
|
258
|
+
"\x0D\x47\xA1"
|
259
|
+
"\x0D\x47\xA1"
|
260
|
+
"\x0D\x47\xA1"
|
261
|
+
"\x0D\x47\xA1"
|
262
|
+
"\x0D\x47\xA1"
|
263
|
+
"\x0D\x47\xA1"
|
264
|
+
"\x0D\x47\xA1"
|
265
|
+
"\x0D\x47\xA1"
|
266
|
+
"\x0D\x47\xA1"
|
267
|
+
"\x0D\x47\xA1"
|
268
|
+
"\x0D\x47\xA1"
|
269
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
270
|
+
|
271
|
+
// Blue #1A237E
|
82
272
|
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
83
|
-
"\
|
84
|
-
"\
|
85
|
-
"\
|
86
|
-
"\
|
87
|
-
"\
|
88
|
-
"\
|
89
|
-
"\
|
90
|
-
"\
|
91
|
-
"\
|
92
|
-
"\
|
93
|
-
"\
|
94
|
-
"\
|
95
|
-
"\
|
96
|
-
"\
|
97
|
-
"\
|
273
|
+
"\x1A\x23\x7E"
|
274
|
+
"\x1A\x23\x7E"
|
275
|
+
"\x1A\x23\x7E"
|
276
|
+
"\x1A\x23\x7E"
|
277
|
+
"\x1A\x23\x7E"
|
278
|
+
"\x1A\x23\x7E"
|
279
|
+
"\x1A\x23\x7E"
|
280
|
+
"\x1A\x23\x7E"
|
281
|
+
"\x1A\x23\x7E"
|
282
|
+
"\x1A\x23\x7E"
|
283
|
+
"\x1A\x23\x7E"
|
284
|
+
"\x1A\x23\x7E"
|
285
|
+
"\x1A\x23\x7E"
|
286
|
+
"\x1A\x23\x7E"
|
287
|
+
"\x1A\x23\x7E"
|
288
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
289
|
+
|
290
|
+
// Blue #0091EA
|
291
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
292
|
+
"\x00\x91\xEA"
|
293
|
+
"\x00\x91\xEA"
|
294
|
+
"\x00\x91\xEA"
|
295
|
+
"\x00\x91\xEA"
|
296
|
+
"\x00\x91\xEA"
|
297
|
+
"\x00\x91\xEA"
|
298
|
+
"\x00\x91\xEA"
|
299
|
+
"\x00\x91\xEA"
|
300
|
+
"\x00\x91\xEA"
|
301
|
+
"\x00\x91\xEA"
|
302
|
+
"\x00\x91\xEA"
|
303
|
+
"\x00\x91\xEA"
|
304
|
+
"\x00\x91\xEA"
|
305
|
+
"\x00\x91\xEA"
|
306
|
+
"\x00\x91\xEA"
|
98
307
|
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
99
308
|
|
100
309
|
// Deep Purple A700 #6200EA
|
@@ -114,5 +323,43 @@ static char *colors[] = {
|
|
114
323
|
"\x62\x00\xEA"
|
115
324
|
"\x62\x00\xEA"
|
116
325
|
"\x62\x00\xEA"
|
326
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
327
|
+
|
328
|
+
// Pink #F50057
|
329
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
330
|
+
"\xF5\x00\x57"
|
331
|
+
"\xF5\x00\x57"
|
332
|
+
"\xF5\x00\x57"
|
333
|
+
"\xF5\x00\x57"
|
334
|
+
"\xF5\x00\x57"
|
335
|
+
"\xF5\x00\x57"
|
336
|
+
"\xF5\x00\x57"
|
337
|
+
"\xF5\x00\x57"
|
338
|
+
"\xF5\x00\x57"
|
339
|
+
"\xF5\x00\x57"
|
340
|
+
"\xF5\x00\x57"
|
341
|
+
"\xF5\x00\x57"
|
342
|
+
"\xF5\x00\x57"
|
343
|
+
"\xF5\x00\x57"
|
344
|
+
"\xF5\x00\x57"
|
345
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
346
|
+
|
347
|
+
// Deep Purple A700 #4A148C
|
348
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
349
|
+
"\x49\x14\x8C"
|
350
|
+
"\x49\x14\x8C"
|
351
|
+
"\x49\x14\x8C"
|
352
|
+
"\x49\x14\x8C"
|
353
|
+
"\x49\x14\x8C"
|
354
|
+
"\x49\x14\x8C"
|
355
|
+
"\x49\x14\x8C"
|
356
|
+
"\x49\x14\x8C"
|
357
|
+
"\x49\x14\x8C"
|
358
|
+
"\x49\x14\x8C"
|
359
|
+
"\x49\x14\x8C"
|
360
|
+
"\x49\x14\x8C"
|
361
|
+
"\x49\x14\x8C"
|
362
|
+
"\x49\x14\x8C"
|
363
|
+
"\x49\x14\x8C"
|
117
364
|
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04"
|
118
365
|
};
|
data/ext/rucaptcha/rucaptcha.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// http://github.com/ITikhonov/captcha
|
2
2
|
const int gifsize;
|
3
|
-
void captcha(unsigned char im[70*200], unsigned char l[8], int length, int i_line, int i_filter);
|
4
|
-
void makegif(unsigned char im[70*200], unsigned char gif[gifsize], int style);
|
3
|
+
void captcha(unsigned char im[70 * 200], unsigned char l[8], int length, int i_line, int i_filter);
|
4
|
+
void makegif(unsigned char im[70 * 200], unsigned char gif[gifsize], int style);
|
5
5
|
|
6
6
|
#include <unistd.h>
|
7
7
|
#include <stdint.h>
|
@@ -14,75 +14,94 @@ void makegif(unsigned char im[70*200], unsigned char gif[gifsize], int style);
|
|
14
14
|
#include "colors.h"
|
15
15
|
|
16
16
|
static int8_t *lt[];
|
17
|
-
const int gifsize=17646;
|
17
|
+
const int gifsize = 17646;
|
18
18
|
|
19
|
-
void makegif(unsigned char im[70*200], unsigned char gif[gifsize], int style)
|
19
|
+
void makegif(unsigned char im[70 * 200], unsigned char gif[gifsize], int style)
|
20
|
+
{
|
20
21
|
// tag ; widthxheight ; GCT:0:0:7 ; bgcolor + aspect // GCT
|
21
22
|
// Image Separator // left x top // widthxheight // Flags
|
22
23
|
// LZW code size
|
23
24
|
srand(time(NULL));
|
24
|
-
int color_len = (int)
|
25
|
+
int color_len = (int)sizeof(colors) / sizeof(colors[0]);
|
25
26
|
int color_idx = rand() % color_len;
|
26
|
-
if (style == 0)
|
27
|
+
if (style == 0)
|
28
|
+
{
|
27
29
|
color_idx = 0;
|
28
30
|
}
|
29
|
-
memcpy(gif,colors[color_idx],13+48+10+1);
|
30
|
-
|
31
|
-
int x,y;
|
32
|
-
unsigned char *i=im;
|
33
|
-
unsigned char *p=gif+13+48+10+1;
|
34
|
-
for(y=0;y<70;y++)
|
35
|
-
|
36
|
-
|
31
|
+
memcpy(gif, colors[color_idx], 13 + 48 + 10 + 1);
|
32
|
+
|
33
|
+
int x, y;
|
34
|
+
unsigned char *i = im;
|
35
|
+
unsigned char *p = gif + 13 + 48 + 10 + 1;
|
36
|
+
for (y = 0; y < 70; y++)
|
37
|
+
{
|
38
|
+
*p++ = 250; // Data length 5*50=250
|
39
|
+
for (x = 0; x < 50; x++)
|
37
40
|
{
|
38
|
-
unsigned char a=i[0]>>4,b=i[1]>>4,c=i[2]>>4,d=i[3]>>4;
|
39
|
-
|
40
|
-
p[0]=16|(a<<5);
|
41
|
-
p[1]=(a>>3)|64|(b<<7);
|
42
|
-
p[2]=b>>1;
|
43
|
-
p[3]=1|(c<<1);
|
44
|
-
p[4]=4|(d<<3);
|
45
|
-
i+=4;
|
46
|
-
p+=5;
|
41
|
+
unsigned char a = i[0] >> 4, b = i[1] >> 4, c = i[2] >> 4, d = i[3] >> 4;
|
42
|
+
|
43
|
+
p[0] = 16 | (a << 5); // bbb10000
|
44
|
+
p[1] = (a >> 3) | 64 | (b << 7); // b10000xb
|
45
|
+
p[2] = b >> 1; // 0000xbbb
|
46
|
+
p[3] = 1 | (c << 1); // 00xbbbb1
|
47
|
+
p[4] = 4 | (d << 3); // xbbbb100
|
48
|
+
i += 4;
|
49
|
+
p += 5;
|
47
50
|
}
|
48
51
|
}
|
49
52
|
|
50
53
|
// Data length // End of LZW (b10001) // Terminator // GIF End
|
51
|
-
memcpy(gif+gifsize-4,"\x01"
|
54
|
+
memcpy(gif + gifsize - 4, "\x01"
|
55
|
+
"\x11"
|
56
|
+
"\x00"
|
57
|
+
";",
|
58
|
+
4);
|
52
59
|
}
|
53
60
|
|
54
|
-
static const int8_t sw[200]={0, 4, 8, 12, 16, 20, 23, 27, 31, 35, 39, 43, 47, 50, 54, 58, 61, 65, 68, 71, 75, 78, 81, 84, 87, 90, 93, 96, 98, 101, 103, 105, 108, 110, 112, 114, 115, 117, 119, 120, 121, 122, 123, 124, 125, 126, 126, 127, 127, 127, 127, 127, 127, 127, 126, 126, 125, 124, 123, 122, 121, 120, 119, 117, 115, 114, 112, 110, 108, 105, 103, 101, 98, 96, 93, 90, 87, 84, 81, 78, 75, 71, 68, 65, 61, 58, 54, 50, 47, 43, 39, 35, 31, 27, 23, 20, 16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -23, -27, -31, -35, -39, -43, -47, -50, -54, -58, -61, -65, -68, -71, -75, -78, -81, -84, -87, -90, -93, -96, -98, -101, -103, -105, -108, -110, -112, -114, -115, -117, -119, -120, -121, -122, -123, -124, -125, -126, -126, -127, -127, -127, -127, -127, -127, -127, -126, -126, -125, -124, -123, -122, -121, -120, -119, -117, -115, -114, -112, -110, -108, -105, -103, -101, -98, -96, -93, -90, -87, -84, -81, -78, -75, -71, -68, -65, -61, -58, -54, -50, -47, -43, -39, -35, -31, -27, -23, -20, -16, -12, -8, -4};
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
int8_t *p=lt[n];
|
61
|
-
unsigned char *r=im+200*16+pos;
|
62
|
-
unsigned char *i=r;
|
63
|
-
int sk1=s1+pos;
|
64
|
-
int sk2=s2+pos;
|
65
|
-
int mpos=pos;
|
66
|
-
int row=0;
|
67
|
-
for(
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
static const int8_t sw[200] = {0, 4, 8, 12, 16, 20, 23, 27, 31, 35, 39, 43, 47, 50, 54, 58, 61, 65, 68, 71, 75, 78, 81, 84, 87, 90, 93, 96, 98, 101, 103, 105, 108, 110, 112, 114, 115, 117, 119, 120, 121, 122, 123, 124, 125, 126, 126, 127, 127, 127, 127, 127, 127, 127, 126, 126, 125, 124, 123, 122, 121, 120, 119, 117, 115, 114, 112, 110, 108, 105, 103, 101, 98, 96, 93, 90, 87, 84, 81, 78, 75, 71, 68, 65, 61, 58, 54, 50, 47, 43, 39, 35, 31, 27, 23, 20, 16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -23, -27, -31, -35, -39, -43, -47, -50, -54, -58, -61, -65, -68, -71, -75, -78, -81, -84, -87, -90, -93, -96, -98, -101, -103, -105, -108, -110, -112, -114, -115, -117, -119, -120, -121, -122, -123, -124, -125, -126, -126, -127, -127, -127, -127, -127, -127, -127, -126, -126, -125, -124, -123, -122, -121, -120, -119, -117, -115, -114, -112, -110, -108, -105, -103, -101, -98, -96, -93, -90, -87, -84, -81, -78, -75, -71, -68, -65, -61, -58, -54, -50, -47, -43, -39, -35, -31, -27, -23, -20, -16, -12, -8, -4};
|
62
|
+
|
63
|
+
#define MAX(x, y) ((x > y) ? (x) : (y))
|
64
|
+
|
65
|
+
static int letter(int n, int pos, unsigned char im[70 * 200], unsigned char swr[200], uint8_t s1, uint8_t s2)
|
66
|
+
{
|
67
|
+
int8_t *p = lt[n];
|
68
|
+
unsigned char *r = im + 200 * 16 + pos;
|
69
|
+
unsigned char *i = r;
|
70
|
+
int sk1 = s1 + pos;
|
71
|
+
int sk2 = s2 + pos;
|
72
|
+
int mpos = pos;
|
73
|
+
int row = 0;
|
74
|
+
for (; *p != -101; p++)
|
75
|
+
{
|
76
|
+
if (*p < 0)
|
77
|
+
{
|
78
|
+
if (*p == -100)
|
79
|
+
{
|
80
|
+
r += 200;
|
81
|
+
i = r;
|
82
|
+
sk1 = s1 + pos;
|
83
|
+
row++;
|
84
|
+
continue;
|
85
|
+
}
|
86
|
+
i += -*p;
|
71
87
|
continue;
|
72
88
|
}
|
73
89
|
|
74
|
-
if(sk1>=200)
|
75
|
-
|
76
|
-
sk1
|
90
|
+
if (sk1 >= 200)
|
91
|
+
sk1 = sk1 % 200;
|
92
|
+
int skew = sw[sk1] / 16;
|
93
|
+
sk1 += (swr[pos + i - r] & 0x1) + 1;
|
77
94
|
|
78
|
-
if(sk2>=200)
|
79
|
-
|
80
|
-
sk2
|
95
|
+
if (sk2 >= 200)
|
96
|
+
sk2 = sk2 % 200;
|
97
|
+
int skewh = sw[sk2] / 70;
|
98
|
+
sk2 += (swr[row] & 0x1);
|
81
99
|
|
82
|
-
unsigned char *x=i+skew*200+skewh;
|
83
|
-
mpos=MAX(mpos,pos+i-r);
|
100
|
+
unsigned char *x = i + skew * 200 + skewh;
|
101
|
+
mpos = MAX(mpos, pos + i - r);
|
84
102
|
|
85
|
-
if((x-im)<70*200)
|
103
|
+
if ((x - im) < 70 * 200)
|
104
|
+
*x = (*p) << 4;
|
86
105
|
i++;
|
87
106
|
}
|
88
107
|
return mpos + 3;
|
@@ -92,100 +111,141 @@ static int letter(int n, int pos, unsigned char im[70*200], unsigned char swr[20
|
|
92
111
|
|
93
112
|
uint32_t dr[NDOTS];
|
94
113
|
|
95
|
-
static void line(unsigned char im[70*200], unsigned char swr[200], uint8_t s1)
|
114
|
+
static void line(unsigned char im[70 * 200], unsigned char swr[200], uint8_t s1)
|
115
|
+
{
|
96
116
|
int x;
|
97
|
-
int sk1=s1;
|
98
|
-
for(x=0;x<199;x++)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
117
|
+
int sk1 = s1;
|
118
|
+
for (x = 0; x < 199; x++)
|
119
|
+
{
|
120
|
+
if (sk1 >= 200)
|
121
|
+
sk1 = sk1 % 200;
|
122
|
+
int skew = sw[sk1] / 20;
|
123
|
+
sk1 += swr[x] & 0x3 + 1;
|
124
|
+
unsigned char *i = im + (200 * (45 + skew) + x);
|
125
|
+
i[0] = 0;
|
126
|
+
i[1] = 0;
|
127
|
+
i[2] = 0;
|
128
|
+
i[3] = 0;
|
129
|
+
i[4] = 0;
|
130
|
+
i[195] = 0;
|
131
|
+
i[196] = 0;
|
132
|
+
i[197] = 0;
|
133
|
+
i[198] = 0;
|
134
|
+
i[200] = 0;
|
104
135
|
}
|
105
136
|
}
|
106
137
|
|
107
|
-
static void dots(unsigned char im[70*200])
|
138
|
+
static void dots(unsigned char im[70 * 200])
|
139
|
+
{
|
108
140
|
int n;
|
109
|
-
for(n=0;n<NDOTS;n++)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
i[
|
115
|
-
i[
|
116
|
-
i[
|
117
|
-
i[
|
118
|
-
i[
|
141
|
+
for (n = 0; n < NDOTS; n++)
|
142
|
+
{
|
143
|
+
uint32_t v = dr[n];
|
144
|
+
unsigned char *i = im + v % (200 * 67);
|
145
|
+
|
146
|
+
i[0] = 0xff;
|
147
|
+
i[1] = 0xff;
|
148
|
+
i[2] = 0xff;
|
149
|
+
i[200] = 0xff;
|
150
|
+
i[201] = 0xff;
|
151
|
+
i[202] = 0xff;
|
119
152
|
}
|
120
153
|
}
|
121
154
|
|
122
|
-
static void blur(unsigned char im[70*200])
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
155
|
+
static void blur(unsigned char im[70 * 200])
|
156
|
+
{
|
157
|
+
unsigned char *i = im;
|
158
|
+
int x, y;
|
159
|
+
for (y = 0; y < 68; y++)
|
160
|
+
{
|
161
|
+
for (x = 0; x < 198; x++)
|
162
|
+
{
|
163
|
+
unsigned int c11 = *i, c12 = i[1], c21 = i[200], c22 = i[201];
|
164
|
+
*i++ = ((c11 + c12 + c21 + c22) / 4);
|
129
165
|
}
|
130
166
|
}
|
131
167
|
}
|
132
168
|
|
133
|
-
static void filter(unsigned char im[70*200])
|
134
|
-
|
135
|
-
unsigned char *
|
136
|
-
unsigned char *
|
169
|
+
static void filter(unsigned char im[70 * 200])
|
170
|
+
{
|
171
|
+
unsigned char om[70 * 200];
|
172
|
+
unsigned char *i = im;
|
173
|
+
unsigned char *o = om;
|
137
174
|
|
138
|
-
memset(om,0xff,sizeof(om));
|
175
|
+
memset(om, 0xff, sizeof(om));
|
139
176
|
|
140
|
-
int x,y;
|
141
|
-
for(y=0;y<70;y++)
|
142
|
-
|
143
|
-
|
144
|
-
|
177
|
+
int x, y;
|
178
|
+
for (y = 0; y < 70; y++)
|
179
|
+
{
|
180
|
+
for (x = 4; x < 200 - 4; x++)
|
181
|
+
{
|
182
|
+
if (i[0] > 0xf0 && i[1] < 0xf0)
|
183
|
+
{
|
184
|
+
o[0] = 0;
|
185
|
+
o[1] = 0;
|
186
|
+
}
|
187
|
+
else if (i[0] < 0xf0 && i[1] > 0xf0)
|
188
|
+
{
|
189
|
+
o[0] = 0;
|
190
|
+
o[1] = 0;
|
191
|
+
}
|
145
192
|
|
146
193
|
i++;
|
147
194
|
o++;
|
148
195
|
}
|
149
196
|
}
|
150
197
|
|
151
|
-
memmove(im,om,sizeof(om));
|
198
|
+
memmove(im, om, sizeof(om));
|
152
199
|
}
|
153
200
|
|
154
|
-
static const char *letters="abcdafahijklmnopqrstuvwxyz";
|
201
|
+
static const char *letters = "abcdafahijklmnopqrstuvwxyz";
|
155
202
|
|
156
|
-
void captcha(unsigned char im[70*200], unsigned char l[8], int length, int i_line, int i_filter)
|
203
|
+
void captcha(unsigned char im[70 * 200], unsigned char l[8], int length, int i_line, int i_filter)
|
204
|
+
{
|
157
205
|
unsigned char swr[200];
|
158
|
-
uint8_t s1,s2;
|
159
|
-
|
160
|
-
int f=open("/dev/urandom",O_RDONLY);
|
161
|
-
read(f,l,5);
|
206
|
+
uint8_t s1, s2;
|
207
|
+
|
208
|
+
int f = open("/dev/urandom", O_RDONLY);
|
209
|
+
read(f, l, 5);
|
210
|
+
read(f, swr, 200);
|
211
|
+
read(f, dr, sizeof(dr));
|
212
|
+
read(f, &s1, 1);
|
213
|
+
read(f, &s2, 1);
|
162
214
|
close(f);
|
163
|
-
memset(im,0xff,200*70);
|
215
|
+
memset(im, 0xff, 200 * 70);
|
216
|
+
s1 = s1 & 0x7f;
|
217
|
+
s2 = s2 & 0x3f;
|
164
218
|
|
165
219
|
int x;
|
166
|
-
for(x=0;x<length;x++)
|
167
|
-
|
220
|
+
for (x = 0; x < length; x++)
|
221
|
+
{
|
222
|
+
l[x] %= 25;
|
168
223
|
}
|
169
|
-
for(x=length;x<8;x++)
|
170
|
-
|
224
|
+
for (x = length; x < 8; x++)
|
225
|
+
{
|
226
|
+
l[length] = 0;
|
171
227
|
}
|
172
228
|
//l[0]%=25; l[1]%=25; l[2]%=25; l[3]%=25; l[4]=0; // l[4]%=25; l[5]=0;
|
173
|
-
int p=30;
|
174
|
-
for(x=0;x<length;x++)
|
175
|
-
|
229
|
+
int p = 30;
|
230
|
+
for (x = 0; x < length; x++)
|
231
|
+
{
|
232
|
+
p = letter(l[x], p, im, swr, s1, s2);
|
176
233
|
}
|
177
234
|
|
178
|
-
if (i_line == 1)
|
179
|
-
|
235
|
+
if (i_line == 1)
|
236
|
+
{
|
237
|
+
line(im, swr, s1);
|
180
238
|
}
|
181
|
-
|
182
|
-
if (i_filter == 1)
|
239
|
+
dots(im);
|
240
|
+
if (i_filter == 1)
|
241
|
+
{
|
183
242
|
blur(im);
|
184
243
|
filter(im);
|
185
244
|
}
|
186
245
|
|
187
|
-
for(x=0;x<length;x++)
|
188
|
-
|
246
|
+
for (x = 0; x < length; x++)
|
247
|
+
{
|
248
|
+
l[x] = letters[l[x]];
|
189
249
|
}
|
190
250
|
//l[1]=letters[l[1]]; l[2]=letters[l[2]]; l[3]=letters[l[3]]; //l[4]=letters[l[4]];
|
191
251
|
}
|
@@ -214,14 +274,16 @@ void Init_rucaptcha();
|
|
214
274
|
|
215
275
|
VALUE create(VALUE self, VALUE style, VALUE length, VALUE line, VALUE filter);
|
216
276
|
|
217
|
-
void Init_rucaptcha()
|
277
|
+
void Init_rucaptcha()
|
278
|
+
{
|
218
279
|
RuCaptcha = rb_define_module("RuCaptcha");
|
219
280
|
rb_define_singleton_method(RuCaptcha, "create", create, 4);
|
220
281
|
}
|
221
282
|
|
222
|
-
VALUE create(VALUE self, VALUE style, VALUE length, VALUE line, VALUE filter)
|
283
|
+
VALUE create(VALUE self, VALUE style, VALUE length, VALUE line, VALUE filter)
|
284
|
+
{
|
223
285
|
char l[8];
|
224
|
-
unsigned char im[80*200];
|
286
|
+
unsigned char im[80 * 200];
|
225
287
|
unsigned char gif[gifsize];
|
226
288
|
int i_style = FIX2INT(style);
|
227
289
|
int i_length = FIX2INT(length);
|
@@ -237,4 +299,3 @@ VALUE create(VALUE self, VALUE style, VALUE length, VALUE line, VALUE filter) {
|
|
237
299
|
|
238
300
|
return result;
|
239
301
|
}
|
240
|
-
|
data/lib/rucaptcha/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rucaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.2.3
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: This is a Captcha gem for Rails Applications. It drawing captcha image with
|