PageSourceSearch

https://www.cqu.edu.cn/system/resource/js/base64.js

js cqu.edu.cn collected 2026-09-24 08:50:17 UTC 4,749 bytes, 139 lines download raw bytes

1/**  
2*  
3*  Base64 encode / decode  
4*  文字采用UTF-8方式进行Base64编码
5*  
6*/  
7    
8function Base64() {   
9    
10    // private property   
11    _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";   
12    
13    // public method for encoding   
14    this.encode = function (input) {   
15        var output=new Array();
16        var chr1, chr2, chr3;
17        var enc1, enc2, enc3, enc4;   
18        var i = 0;   
19        input = _utf8_encode(input);   
20        
21        while (i < input.length) 
22        {   
23            chr1 = input[i++];
24            chr2 = input[i++];
25            chr3 = input[i++];
26    
27            enc1 = chr1 >> 2;   
28            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);   
29            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);   
30            enc4 = chr3 & 63;   
31            if (isNaN(chr2)) {   
32                enc3 = enc4 = 64;   
33            } else if (isNaN(chr3)) {   
34                enc4 = 64;   
35            }   
36            output.push(_keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4));   
37        }   
38        return output.join('');
39    }   
40    
41    // public method for decoding   
42    this.decode = function (input) {   
43        var output = "";   
44        var chr1, chr2, chr3;   
45        var enc1, enc2, enc3, enc4;   
46        var i = 0;   
47        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");   
48        while (i < input.length) {   
49            enc1 = _keyStr.indexOf(input.charAt(i++));   
50            enc2 = _keyStr.indexOf(input.charAt(i++));   
51            enc3 = _keyStr.indexOf(input.charAt(i++));   
52            enc4 = _keyStr.indexOf(input.charAt(i++));   
53            chr1 = (enc1 << 2) | (enc2 >> 4);   
54            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);   
55            chr3 = ((enc3 & 3) << 6) | enc4;   
56            output = output + String.fromCharCode(chr1);   
57            if (enc3 != 64) {   
58                output = output + String.fromCharCode(chr2);   
59            }   
60            if (enc4 != 64) {   
61                output = output + String.fromCharCode(chr3);   
62            }   
63        }   
64        output = _utf8_decode(output);   
65        return output;   
66    }   
67    
68    // private method for UTF-8 encoding   
69    _utf8_encode = function (string) {   
70        string = string.replace(/\r\n/g,"\n");   
71        var utftext = new Array();
72        var utftextlen=0;
73        for (var n = 0; n < string.length; n++) {   
74            var c = string.charCodeAt(n);   
75            if (c < 128) {   
76                utftext[utftextlen++] = c;
77            } else if((c > 127) && (c < 2048)) {   
78                utftext[utftextlen++] = (c >> 6) | 192;
79                utftext[utftextlen++] = (c & 63) | 128;
80            } else {   
81                utftext[utftextlen++] = (c >> 12) | 224;
82                utftext[utftextlen++] = ((c >> 6) & 63) | 128;
83                utftext[utftextlen++] = (c & 63) | 128;   
84            }   
85    
86        }   
87        return utftext;   
88    }   
89    
90    // private method for UTF-8 decoding   
91    _utf8_decode = function (utftext) {   
92        var string = "";   
93        var i = 0;   
94        var c = c1 = c2 = 0;   
95        while ( i < utftext.length ) {   
96            c = utftext.charCodeAt(i);   
97            if (c < 128) {   
98                string += String.fromCharCode(c);   
99                i++;   
100            } else if((c > 191) && (c < 224)) {   
101                c2 = utftext.charCodeAt(i+1);   
102                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));   
103                i += 2;   
104            } else {   
105                c2 = utftext.charCodeAt(i+1);   
106                c3 = utftext.charCodeAt(i+2);   
107                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));   
108                i += 3;   
109            }   
110        }   
111        return string;   
112    }   
113    
114    _exchange_character = function(charArray){
115    	charArray=charArray.split("");
116		for (var i = 0; i < charArray.length; i++)
117		{
118			// 互换相邻的字符
119			if (i > 0 && i % 2 == 0)
120			{
121				var c = charArray[i];
122				charArray[i] = charArray[i - 1];
123				charArray[i - 1] = c;
124			}
125		}
126		return charArray.join("");
127    }
128    
129    //参数需要绕过防火墙可使用此方法加密
130    this.encodePostParam = function(input) {
131    	input=this.encode(input).split("").reverse().join("");
132    	return _exchange_character(input);
133    }
134    
135    this.decodePostParam = function(input) {
136    	input=_exchange_character(input).split("").reverse().join("");
137    	return this.decode(input);
138    }
139}  

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.