PageSourceSearch

https://eamic.elda.es:20443/js/base64.js

js elda.es collected 2026-10-02 11:51:39 UTC 8,809 bytes, 301 lines download raw bytes

1var Base64 = {
2
3    // private property
4    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
5
6    // public method for encoding
7    encode : function (input) {
8        var output = "";
9        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
10        var i = 0;
11
12        input = Base64._utf8_encode(input);
13
14        while (i < input.length) {
15
16            chr1 = input.charCodeAt(i++);
17            chr2 = input.charCodeAt(i++);
18            chr3 = input.charCodeAt(i++);
19
20            enc1 = chr1 >> 2;
21            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
22            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
23            enc4 = chr3 & 63;
24
25            if (isNaN(chr2)) {
26                enc3 = enc4 = 64;
27            } else if (isNaN(chr3)) {
28                enc4 = 64;
29            }
30
31            output = output +
32            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
33            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
34
35        }
36
37        return output;
38    },
39    encodeURL : function (input) {
40        var output = "";
41        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
42        var i = 0;
43
44        input = Base64._utf8_encode(input);
45
46        while (i < input.length) {
47
48            chr1 = input.charCodeAt(i++);
49            chr2 = input.charCodeAt(i++);
50            chr3 = input.charCodeAt(i++);
51
52            enc1 = chr1 >> 2;
53            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
54            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
55            enc4 = chr3 & 63;
56
57            if (isNaN(chr2)) {
58                enc3 = enc4 = 64;
59            } else if (isNaN(chr3)) {
60                enc4 = 64;
61            }
62
63            output = output +
64            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
65            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
66
67        }
68		output = output.replace(/\+/g,"-");
69		output = output.replace(/\//g,"_");
70        return output;
71    },
72
73    // public method for decoding
74    decode : function (input) {
75        var output = "";
76        var chr1, chr2, chr3;
77        var enc1, enc2, enc3, enc4;
78        var i = 0;
79
80        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
81
82        while (i < input.length) {
83
84            enc1 = this._keyStr.indexOf(input.charAt(i++));
85            enc2 = this._keyStr.indexOf(input.charAt(i++));
86            enc3 = this._keyStr.indexOf(input.charAt(i++));
87            enc4 = this._keyStr.indexOf(input.charAt(i++));
88
89            chr1 = (enc1 << 2) | (enc2 >> 4);
90            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
91            chr3 = ((enc3 & 3) << 6) | enc4;
92
93            output = output + String.fromCharCode(chr1);
94
95            if (enc3 != 64) {
96                output = output + String.fromCharCode(chr2);
97            }
98            if (enc4 != 64) {
99                output = output + String.fromCharCode(chr3);
100            }
101
102        }
103
104        output = Base64._utf8_decode(output);
105
106        return output;
107
108    },
109    decodeURL : function (input) {
110		input = input.replace(/-/g,"+");
111		input = input.replace(/_/g,"/");
112        var output = "";
113        var chr1, chr2, chr3;
114        var enc1, enc2, enc3, enc4;
115        var i = 0;
116
117        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
118
119        while (i < input.length) {
120
121            enc1 = this._keyStr.indexOf(input.charAt(i++));
122            enc2 = this._keyStr.indexOf(input.charAt(i++));
123            enc3 = this._keyStr.indexOf(input.charAt(i++));
124            enc4 = this._keyStr.indexOf(input.charAt(i++));
125
126            chr1 = (enc1 << 2) | (enc2 >> 4);
127            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
128            chr3 = ((enc3 & 3) << 6) | enc4;
129
130            output = output + String.fromCharCode(chr1);
131
132            if (enc3 != 64) {
133                output = output + String.fromCharCode(chr2);
134            }
135            if (enc4 != 64) {
136                output = output + String.fromCharCode(chr3);
137            }
138
139        }
140
141        output = Base64._utf8_decode(output);
142
143        return output;
144
145    },
146
147    // private method for UTF-8 encoding
148    _utf8_encode : function (string) {
149        string = string.replace(/\r\n/g,"\n");
150        var utftext = "";
151
152        for (var n = 0; n < string.length; n++) {
153
154            var c = string.charCodeAt(n);
155
156            if (c < 128) {
157                utftext += String.fromCharCode(c);
158            }
159            else if((c > 127) && (c < 2048)) {
160                utftext += String.fromCharCode((c >> 6) | 192);
161                utftext += String.fromCharCode((c & 63) | 128);
162            }
163            else {
164                utftext += String.fromCharCode((c >> 12) | 224);
165                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
166                utftext += String.fromCharCode((c & 63) | 128);
167            }
168
169        }
170
171        return utftext;
172    },
173
174    // private method for UTF-8 decoding
175    _utf8_decode : function (utftext) {
176        var string = "";
177        var i = 0;
178        var c = c1 = c2 = 0;
179
180        while ( i < utftext.length ) {
181
182            c = utftext.charCodeAt(i);
183
184            if (c < 128) {
185                string += String.fromCharCode(c);
186                i++;
187            }
188            else if((c > 191) && (c < 224)) {
189                c2 = utftext.charCodeAt(i+1);
190                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
191                i += 2;
192            }
193            else {
194                c2 = utftext.charCodeAt(i+1);
195                c3 = utftext.charCodeAt(i+2);
196                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
197                i += 3;
198            }
199
200        }
201
202        return string;
203    }
204
205}
206
207
208function clean_hex(input, remove_0x) {
209        input = input.toUpperCase();
210        
211        if (remove_0x) {
212          input = input.replace(/0x/gi, "");        
213        }
214        
215        var orig_input = input;
216        input = input.replace(/[^A-Fa-f0-9]/g, "");
217        if (orig_input != input)
218            alert ("Warning! Non-hex characters in input string ignored.");
219        return input;    
220    }
221 
222    var base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
223    function binary_to_base64(input) {
224      var ret = new Array();
225      var i = 0;
226      var j = 0;
227      var char_array_3 = new Array(3);
228      var char_array_4 = new Array(4);
229      var in_len = input.length;
230      var pos = 0;
231  
232      while (in_len--)
233      {
234          char_array_3[i++] = input[pos++];
235          if (i == 3)
236          {
237              char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
238              char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
239              char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
240              char_array_4[3] = char_array_3[2] & 0x3f;
241  
242              for (i = 0; (i <4) ; i++)
243                  ret += base64_chars.charAt(char_array_4[i]);
244              i = 0;
245          }
246      }
247  
248      if (i)
249      {
250          for (j = i; j < 3; j++)
251              char_array_3[j] = 0;
252  
253          char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
254          char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
255          char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
256          char_array_4[3] = char_array_3[2] & 0x3f;
257  
258          for (j = 0; (j < i + 1); j++)
259              ret += base64_chars.charAt(char_array_4[j]);
260  
261          while ((i++ < 3))
262              ret += '=';
263  
264      }
265  
266      return ret;
267    }
268    
269    function ConvertHexToB64(Shahex) {
270      var cleaned_hex = clean_hex(Shahex, false);
271      if (cleaned_hex.length % 2) {
272        alert ("Error: cleaned hex string length is odd.");
273        document.frmConvert.base64.value = "";        
274        return;
275      }
276      var binary = new Array();
277      for (var i=0; i<cleaned_hex.length/2; i++) {
278        var h = cleaned_hex.substr(i*2, 2);
279        binary[i] = parseInt(h,16);        
280      }
281      return binary_to_base64(binary);
282    } 
283	
284	function dec2hex(str){ // .toString(16) only works up to 2^53
285    var dec = str.toString().split(''), sum = [], hex = [], i, s
286    while(dec.length){
287        s = 1 * dec.shift()
288        for(i = 0; s || i < sum.length; i++){
289            s += (sum[i] || 0) * 10
290            sum[i] = s % 16
291            s = (s - sum[i]) / 16
292        }
293    }
294    while(sum.length){
295        hex.push(sum.pop().toString(16))
296    }
297    return hex.join('')
298}
299
300	
301	

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.