PageSourceSearch

http://cessp.org.cn/js/base64.js

js cessp.org.cn collected 2026-10-04 00:51:05 UTC 3,217 bytes, 106 lines download raw bytes

1/**
2*
3* Base64 encode / decode
4*
5* @author haitao.tu
6* @date 2010-04-26
7* @email [email protected]
8*
9*/
10function Base64() {
11    // private property
12    _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
13    // public method for encoding
14    this.encode = function (input) {
15     var output = "";
16     var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
17     var i = 0;
18     input = _utf8_encode(input);
19     while (i < input.length) {
20      chr1 = input.charCodeAt(i++);
21      chr2 = input.charCodeAt(i++);
22      chr3 = input.charCodeAt(i++);
23      enc1 = chr1 >> 2;
24      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
25      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
26      enc4 = chr3 & 63;
27      if (isNaN(chr2)) {
28       enc3 = enc4 = 64;
29      } else if (isNaN(chr3)) {
30       enc4 = 64;
31      }
32      output = output +
33      _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
34      _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
35     }
36     return output;
37    }
38    // public method for decoding
39    this.decode = function (input) {
40     var output = "";
41     var chr1, chr2, chr3;
42     var enc1, enc2, enc3, enc4;
43     var i = 0;
44     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
45     while (i < input.length) {
46      enc1 = _keyStr.indexOf(input.charAt(i++));
47      enc2 = _keyStr.indexOf(input.charAt(i++));
48      enc3 = _keyStr.indexOf(input.charAt(i++));
49      enc4 = _keyStr.indexOf(input.charAt(i++));
50      chr1 = (enc1 << 2) | (enc2 >> 4);
51      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
52      chr3 = ((enc3 & 3) << 6) | enc4;
53      output = output + String.fromCharCode(chr1);
54      if (enc3 != 64) {
55       output = output + String.fromCharCode(chr2);
56      }
57      if (enc4 != 64) {
58       output = output + String.fromCharCode(chr3);
59      }
60     }
61     output = _utf8_decode(output);
62     return output;
63    }
64    // private method for UTF-8 encoding
65    _utf8_encode = function (string) {
66     string = string && string.replace(/\r\n/g,"\n");
67     var utftext = "";
68     for (var n = 0; n < string.length; n++) {
69      var c = string.charCodeAt(n);
70      if (c < 128) {
71       utftext += String.fromCharCode(c);
72      } else if((c > 127) && (c < 2048)) {
73       utftext += String.fromCharCode((c >> 6) | 192);
74       utftext += String.fromCharCode((c & 63) | 128);
75      } else {
76       utftext += String.fromCharCode((c >> 12) | 224);
77       utftext += String.fromCharCode(((c >> 6) & 63) | 128);
78       utftext += String.fromCharCode((c & 63) | 128);
79      }
80     }
81     return utftext;
82    }
83    // private method for UTF-8 decoding
84    _utf8_decode = function (utftext) {
85     var string = "";
86     var i = 0;
87     var c = c1 = c2 = 0;
88     while ( i < utftext.length ) {
89      c = utftext.charCodeAt(i);
90      if (c < 128) {
91       string += String.fromCharCode(c);
92       i++;
93      } else if((c > 191) && (c < 224)) {
94       c2 = utftext.charCodeAt(i+1);
95       string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
96       i += 2;
97      } else {
98       c2 = utftext.charCodeAt(i+1);
99       c3 = utftext.charCodeAt(i+2);
100       string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
101       i += 3;
102      }
103     }
104     return string;
105    }
106   }   

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.