light-h5-core-lib 2.8.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LightCore.ts +49 -0
- package/common/base/BaseSingleton.ts +28 -0
- package/common/base/IClear.ts +5 -0
- package/common/base/IDestroy.ts +3 -0
- package/common/md5/{MD5.js → MD5.ts} +376 -346
- package/common/util/BeizerUtil.ts +87 -0
- package/common/util/{BitUtil.js → BitUtil.ts} +37 -43
- package/common/util/BooleanUtil.ts +15 -0
- package/common/util/Crc32Util.ts +30 -0
- package/common/util/DateUtil.ts +120 -0
- package/common/util/FloatDigitUtil.ts +55 -0
- package/common/util/NumberUtil.ts +15 -0
- package/common/util/PromiseUtil.ts +25 -0
- package/common/util/RandomNumUtil.ts +81 -0
- package/common/util/SelfDecrypt.ts +31 -0
- package/common/util/StringUtil.ts +83 -0
- package/common/util/UniqueIDUtil.ts +14 -0
- package/package.json +1 -1
- package/pool/PoolObj.ts +69 -0
- package/type/index.d.ts +81 -3
- package/LightCore.js +0 -44
- package/common/base/BaseSingleton.js +0 -23
- package/common/base/IClear.js +0 -2
- package/common/base/IDestroy.js +0 -2
- package/common/util/BeizerUtil.js +0 -83
- package/common/util/Crc32Util.js +0 -35
- package/common/util/CryptUtil.js +0 -43
- package/common/util/DateUtil.js +0 -89
- package/common/util/FloatDigitUtil.js +0 -22
- package/common/util/PromiseUtil.js +0 -74
- package/common/util/RandomNumUtil.js +0 -54
- package/common/util/StringUtil.js +0 -81
- package/common/util/UniqueIDUtil.js +0 -21
- package/pool/PoolObj.js +0 -79
|
@@ -1,346 +1,376 @@
|
|
|
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
|
-
return this.
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var
|
|
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
|
-
if (x <=
|
|
178
|
-
output += String.fromCharCode(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
else if (x <= 0x1fffff)
|
|
184
|
-
output += String.fromCharCode(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var output = "";
|
|
199
|
-
for (var i = 0; i < input.length; i++)
|
|
200
|
-
output += String.fromCharCode(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
var output =
|
|
209
|
-
for (var i = 0; i <
|
|
210
|
-
output
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
var
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
a = this.
|
|
293
|
-
d = this.
|
|
294
|
-
c = this.
|
|
295
|
-
b = this.
|
|
296
|
-
a = this.
|
|
297
|
-
d = this.
|
|
298
|
-
c = this.
|
|
299
|
-
b = this.
|
|
300
|
-
a = this.
|
|
301
|
-
d = this.
|
|
302
|
-
c = this.
|
|
303
|
-
b = this.
|
|
304
|
-
a = this.
|
|
305
|
-
|
|
306
|
-
c = this.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
1
|
+
import {BaseSingleton} from "../base/BaseSingleton";
|
|
2
|
+
|
|
3
|
+
export class MD5 extends BaseSingleton<MD5> {
|
|
4
|
+
private hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
|
5
|
+
private b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
|
6
|
+
|
|
7
|
+
public constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* These are the privates you'll usually want to call
|
|
13
|
+
* They take string arguments and return either hex or base-64 encoded strings
|
|
14
|
+
*/
|
|
15
|
+
public hex_md5(s: string) {
|
|
16
|
+
return this.rstr2hex(this.rstr_md5(this.str2rstr_utf8(s)));
|
|
17
|
+
} //这个函数就行了,
|
|
18
|
+
public b64_md5(s: string) {
|
|
19
|
+
return this.rstr2b64(this.rstr_md5(this.str2rstr_utf8(s)));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public any_md5(s: string, e: string) {
|
|
23
|
+
return this.rstr2any(this.rstr_md5(this.str2rstr_utf8(s)), e);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public hex_hmac_md5(k: string, d: string) {
|
|
27
|
+
return this.rstr2hex(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private b64_hmac_md5(k: string, d: string) {
|
|
31
|
+
return this.rstr2b64(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private any_hmac_md5(k: string, d: string, e: string) {
|
|
35
|
+
return this.rstr2any(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d)), e);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* Perform a simple self-test to see if the VM is working
|
|
40
|
+
*/
|
|
41
|
+
public md5_vm_test() {
|
|
42
|
+
return this.hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Calculate the MD5 of a raw string
|
|
47
|
+
*/
|
|
48
|
+
public rstr_md5(s: string) {
|
|
49
|
+
return this.binl2rstr(this.binl_md5(this.rstr2binl(s), s.length * 8));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Calculate the HMAC-MD5, of a key and some data (raw strings)
|
|
54
|
+
*/
|
|
55
|
+
public rstr_hmac_md5(key: string, data: string) {
|
|
56
|
+
var bkey = this.rstr2binl(key);
|
|
57
|
+
if (bkey.length > 16) bkey = this.binl_md5(bkey, key.length * 8);
|
|
58
|
+
|
|
59
|
+
var ipad = Array(16),
|
|
60
|
+
opad = Array(16);
|
|
61
|
+
for (var i = 0; i < 16; i++) {
|
|
62
|
+
ipad[i] = bkey[i] ^ 0x36363636;
|
|
63
|
+
opad[i] = bkey[i] ^ 0x5c5c5c5c;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var hash = this.binl_md5(ipad.concat(this.rstr2binl(data)), 512 + data.length * 8);
|
|
67
|
+
return this.binl2rstr(this.binl_md5(opad.concat(hash), 512 + 128));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* Convert a raw string to a hex string
|
|
72
|
+
*/
|
|
73
|
+
public rstr2hex(input: string) {
|
|
74
|
+
try {
|
|
75
|
+
this.hexcase;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
this.hexcase = 0;
|
|
78
|
+
}
|
|
79
|
+
var hex_tab = this.hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
|
80
|
+
var output = "";
|
|
81
|
+
var x;
|
|
82
|
+
for (var i = 0; i < input.length; i++) {
|
|
83
|
+
x = input.charCodeAt(i);
|
|
84
|
+
output += hex_tab.charAt((x >>> 4) & 0x0f) + hex_tab.charAt(x & 0x0f);
|
|
85
|
+
}
|
|
86
|
+
return output;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* Convert a raw string to a base-64 string
|
|
91
|
+
*/
|
|
92
|
+
public rstr2b64(input: string) {
|
|
93
|
+
try {
|
|
94
|
+
this.b64pad;
|
|
95
|
+
} catch (e) {
|
|
96
|
+
this.b64pad = "";
|
|
97
|
+
}
|
|
98
|
+
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
99
|
+
var output = "";
|
|
100
|
+
var len = input.length;
|
|
101
|
+
for (var i = 0; i < len; i += 3) {
|
|
102
|
+
var triplet =
|
|
103
|
+
(input.charCodeAt(i) << 16) |
|
|
104
|
+
(i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) |
|
|
105
|
+
(i + 2 < len ? input.charCodeAt(i + 2) : 0);
|
|
106
|
+
for (var j = 0; j < 4; j++) {
|
|
107
|
+
if (i * 8 + j * 6 > input.length * 8) output += this.b64pad;
|
|
108
|
+
else output += tab.charAt((triplet >>> (6 * (3 - j))) & 0x3f);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return output;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
* Convert a raw string to an arbitrary string encoding
|
|
116
|
+
*/
|
|
117
|
+
public rstr2any(input: string, encoding: string) {
|
|
118
|
+
var divisor = encoding.length;
|
|
119
|
+
var i, j, q, x, quotient;
|
|
120
|
+
|
|
121
|
+
/* Convert to an array of 16-bit big-endian values, forming the dividend */
|
|
122
|
+
var dividend = Array(Math.ceil(input.length / 2));
|
|
123
|
+
for (i = 0; i < dividend.length; i++) {
|
|
124
|
+
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
* Repeatedly perform a long division. The binary array forms the dividend,
|
|
129
|
+
* the length of the encoding is the divisor. Once computed, the quotient
|
|
130
|
+
* forms the dividend for the next step. All remainders are stored for later
|
|
131
|
+
* use.
|
|
132
|
+
*/
|
|
133
|
+
var full_length = Math.ceil((input.length * 8) / (Math.log(encoding.length) / Math.log(2)));
|
|
134
|
+
var remainders = Array(full_length);
|
|
135
|
+
for (j = 0; j < full_length; j++) {
|
|
136
|
+
quotient = Array();
|
|
137
|
+
x = 0;
|
|
138
|
+
for (i = 0; i < dividend.length; i++) {
|
|
139
|
+
x = (x << 16) + dividend[i];
|
|
140
|
+
q = Math.floor(x / divisor);
|
|
141
|
+
x -= q * divisor;
|
|
142
|
+
if (quotient.length > 0 || q > 0) quotient[quotient.length] = q;
|
|
143
|
+
}
|
|
144
|
+
remainders[j] = x;
|
|
145
|
+
dividend = quotient;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* Convert the remainders to the output string */
|
|
149
|
+
var output = "";
|
|
150
|
+
for (i = remainders.length - 1; i >= 0; i--) output += encoding.charAt(remainders[i]);
|
|
151
|
+
|
|
152
|
+
return output;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/*
|
|
156
|
+
* Encode a string as utf-8.
|
|
157
|
+
* For efficiency, this assumes the input is valid utf-16.
|
|
158
|
+
*/
|
|
159
|
+
public str2rstr_utf8(input: string) {
|
|
160
|
+
var output = "";
|
|
161
|
+
var i = -1;
|
|
162
|
+
var x, y;
|
|
163
|
+
|
|
164
|
+
while (++i < input.length) {
|
|
165
|
+
/* Decode utf-16 surrogate pairs */
|
|
166
|
+
x = input.charCodeAt(i);
|
|
167
|
+
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
|
|
168
|
+
if (0xd800 <= x && x <= 0xdbff && 0xdc00 <= y && y <= 0xdfff) {
|
|
169
|
+
x = 0x10000 + ((x & 0x03ff) << 10) + (y & 0x03ff);
|
|
170
|
+
i++;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* Encode output as utf-8 */
|
|
174
|
+
if (x <= 0x7f) output += String.fromCharCode(x);
|
|
175
|
+
else if (x <= 0x7ff)
|
|
176
|
+
output += String.fromCharCode(0xc0 | ((x >>> 6) & 0x1f), 0x80 | (x & 0x3f));
|
|
177
|
+
else if (x <= 0xffff)
|
|
178
|
+
output += String.fromCharCode(
|
|
179
|
+
0xe0 | ((x >>> 12) & 0x0f),
|
|
180
|
+
0x80 | ((x >>> 6) & 0x3f),
|
|
181
|
+
0x80 | (x & 0x3f)
|
|
182
|
+
);
|
|
183
|
+
else if (x <= 0x1fffff)
|
|
184
|
+
output += String.fromCharCode(
|
|
185
|
+
0xf0 | ((x >>> 18) & 0x07),
|
|
186
|
+
0x80 | ((x >>> 12) & 0x3f),
|
|
187
|
+
0x80 | ((x >>> 6) & 0x3f),
|
|
188
|
+
0x80 | (x & 0x3f)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
return output;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
* Encode a string as utf-16
|
|
196
|
+
*/
|
|
197
|
+
public str2rstr_utf16le(input: string) {
|
|
198
|
+
var output = "";
|
|
199
|
+
for (var i = 0; i < input.length; i++)
|
|
200
|
+
output += String.fromCharCode(
|
|
201
|
+
input.charCodeAt(i) & 0xff,
|
|
202
|
+
(input.charCodeAt(i) >>> 8) & 0xff
|
|
203
|
+
);
|
|
204
|
+
return output;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public str2rstr_utf16be(input: string) {
|
|
208
|
+
var output = "";
|
|
209
|
+
for (var i = 0; i < input.length; i++)
|
|
210
|
+
output += String.fromCharCode(
|
|
211
|
+
(input.charCodeAt(i) >>> 8) & 0xff,
|
|
212
|
+
input.charCodeAt(i) & 0xff
|
|
213
|
+
);
|
|
214
|
+
return output;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/*
|
|
218
|
+
* Convert a raw string to an array of little-endian words
|
|
219
|
+
* Characters >255 have their high-byte silently ignored.
|
|
220
|
+
*/
|
|
221
|
+
public rstr2binl(input: string) {
|
|
222
|
+
var output = Array(input.length >> 2);
|
|
223
|
+
for (var i = 0; i < output.length; i++) output[i] = 0;
|
|
224
|
+
for (var i = 0; i < input.length * 8; i += 8)
|
|
225
|
+
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << i % 32;
|
|
226
|
+
return output;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/*
|
|
230
|
+
* Convert an array of little-endian words to a string
|
|
231
|
+
*/
|
|
232
|
+
public binl2rstr(input: number[]) {
|
|
233
|
+
var output = "";
|
|
234
|
+
for (var i = 0; i < input.length * 32; i += 8)
|
|
235
|
+
output += String.fromCharCode((input[i >> 5] >>> i % 32) & 0xff);
|
|
236
|
+
return output;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/*
|
|
240
|
+
* Calculate the MD5 of an array of little-endian words, and a bit length.
|
|
241
|
+
*/
|
|
242
|
+
public binl_md5(x: number[], len: number) {
|
|
243
|
+
/* append padding */
|
|
244
|
+
x[len >> 5] |= 0x80 << len % 32;
|
|
245
|
+
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
|
246
|
+
|
|
247
|
+
var a = 1732584193;
|
|
248
|
+
var b = -271733879;
|
|
249
|
+
var c = -1732584194;
|
|
250
|
+
var d = 271733878;
|
|
251
|
+
|
|
252
|
+
for (var i = 0; i < x.length; i += 16) {
|
|
253
|
+
var olda = a;
|
|
254
|
+
var oldb = b;
|
|
255
|
+
var oldc = c;
|
|
256
|
+
var oldd = d;
|
|
257
|
+
|
|
258
|
+
a = this.md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
|
|
259
|
+
d = this.md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
260
|
+
c = this.md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
261
|
+
b = this.md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
262
|
+
a = this.md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
263
|
+
d = this.md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
264
|
+
c = this.md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
265
|
+
b = this.md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
266
|
+
a = this.md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
267
|
+
d = this.md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
268
|
+
c = this.md5_ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
269
|
+
b = this.md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
270
|
+
a = this.md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
271
|
+
d = this.md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
272
|
+
c = this.md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
273
|
+
b = this.md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
274
|
+
|
|
275
|
+
a = this.md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
276
|
+
d = this.md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
277
|
+
c = this.md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
278
|
+
b = this.md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
|
|
279
|
+
a = this.md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
280
|
+
d = this.md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
281
|
+
c = this.md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
282
|
+
b = this.md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
283
|
+
a = this.md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
284
|
+
d = this.md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
285
|
+
c = this.md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
286
|
+
b = this.md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
287
|
+
a = this.md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
288
|
+
d = this.md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
289
|
+
c = this.md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
290
|
+
b = this.md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
291
|
+
|
|
292
|
+
a = this.md5_hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
293
|
+
d = this.md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
294
|
+
c = this.md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
295
|
+
b = this.md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
296
|
+
a = this.md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
297
|
+
d = this.md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
298
|
+
c = this.md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
299
|
+
b = this.md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
300
|
+
a = this.md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
301
|
+
d = this.md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
|
|
302
|
+
c = this.md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
303
|
+
b = this.md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
304
|
+
a = this.md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
305
|
+
d = this.md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
306
|
+
c = this.md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
307
|
+
b = this.md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
308
|
+
|
|
309
|
+
a = this.md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
|
|
310
|
+
d = this.md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
311
|
+
c = this.md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
312
|
+
b = this.md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
313
|
+
a = this.md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
314
|
+
d = this.md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
315
|
+
c = this.md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
316
|
+
b = this.md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
317
|
+
a = this.md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
318
|
+
d = this.md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
319
|
+
c = this.md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
320
|
+
b = this.md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
321
|
+
a = this.md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
322
|
+
d = this.md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
323
|
+
c = this.md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
324
|
+
b = this.md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
325
|
+
|
|
326
|
+
a = this.safe_add(a, olda);
|
|
327
|
+
b = this.safe_add(b, oldb);
|
|
328
|
+
c = this.safe_add(c, oldc);
|
|
329
|
+
d = this.safe_add(d, oldd);
|
|
330
|
+
}
|
|
331
|
+
return [a, b, c, d];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/*
|
|
335
|
+
* These privates implement the four basic operations the algorithm uses.
|
|
336
|
+
*/
|
|
337
|
+
public md5_cmn(q: any, a: any, b: any, x: any, s: any, t: any) {
|
|
338
|
+
return this.safe_add(
|
|
339
|
+
this.bit_rol(this.safe_add(this.safe_add(a, q), this.safe_add(x, t)), s),
|
|
340
|
+
b
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public md5_ff(a: any, b: any, c: any, d: any, x: any, s: any, t: any) {
|
|
345
|
+
return this.md5_cmn((b & c) | (~b & d), a, b, x, s, t);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
public md5_gg(a: any, b: any, c: any, d: any, x: any, s: any, t: any) {
|
|
349
|
+
return this.md5_cmn((b & d) | (c & ~d), a, b, x, s, t);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
public md5_hh(a: any, b: any, c: any, d: any, x: any, s: any, t: any) {
|
|
353
|
+
return this.md5_cmn(b ^ c ^ d, a, b, x, s, t);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
public md5_ii(a: any, b: any, c: any, d: any, x: any, s: any, t: any) {
|
|
357
|
+
return this.md5_cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/*
|
|
361
|
+
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
|
362
|
+
* to work around bugs in some JS interpreters.
|
|
363
|
+
*/
|
|
364
|
+
public safe_add(x: any, y: any) {
|
|
365
|
+
var lsw = (x & 0xffff) + (y & 0xffff);
|
|
366
|
+
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
367
|
+
return (msw << 16) | (lsw & 0xffff);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/*
|
|
371
|
+
* Bitwise rotate a 32-bit number to the left.
|
|
372
|
+
*/
|
|
373
|
+
public bit_rol(num: any, cnt: any) {
|
|
374
|
+
return (num << cnt) | (num >>> (32 - cnt));
|
|
375
|
+
}
|
|
376
|
+
}
|