PageSourceSearch

https://static.orangenews.hk/static/orange/js/MD5.js

js orangenews.hk collected 2026-09-24 18:16:48 UTC 13,506 bytes, 342 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.