light-h5-core-lib 2.8.2 → 2.8.3

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