PageSourceSearch

https://winway-official.com/js/jQuery.base64.js

js winway-official.com collected 2026-10-04 20:07:11 UTC 4,621 bytes, 143 lines download raw bytes

1	
2	/**
3	 * jQuery BASE64 functions
4	 * 
5	 * 	<code>
6	 * 		Encodes the given data with base64. 
7	 * 		String $.base64Encode ( String str )
8	 *		<br />
9	 * 		Decodes a base64 encoded data.
10	 * 		String $.base64Decode ( String str )
11	 * 	</code>
12	 * 
13	 * Encodes and Decodes the given data in base64.
14	 * This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.
15	 * Base64-encoded data takes about 33% more space than the original data. 
16	 * This javascript code is used to encode / decode data using base64 (this encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean). Script is fully compatible with UTF-8 encoding. You can use base64 encoded data as simple encryption mechanism.
17	 * If you plan using UTF-8 encoding in your project don't forget to set the page encoding to UTF-8 (Content-Type meta tag). 
18	 * This function orginally get from the WebToolkit and rewrite for using as the jQuery plugin.
19	 * 
20	 * Example
21	 * 	Code
22	 * 		<code>
23	 * 			$.base64Encode("I'm Persian."); 
24	 * 		</code>
25	 * 	Result
26	 * 		<code>
27	 * 			"SSdtIFBlcnNpYW4u"
28	 * 		</code>
29	 * 	Code
30	 * 		<code>
31	 * 			$.base64Decode("SSdtIFBlcnNpYW4u");
32	 * 		</code>
33	 * 	Result
34	 * 		<code>
35	 * 			"I'm Persian."
36	 * 		</code>
37	 * 
38	 * @alias Muhammad Hussein Fattahizadeh < muhammad [AT] semnanweb [DOT] com >
39	 * @link http://www.semnanweb.com/jquery-plugin/base64.html (no longer available?)
40	 * @link https://gist.github.com/gists/1602210
41	 * @see http://www.webtoolkit.info/
42	 * @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
43	 * @param {jQuery} {base64Encode:function(input))
44	 * @param {jQuery} {base64Decode:function(input))
45	 * @return string
46	 */
47	
48	(function($){
49		
50		var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
51		
52		var uTF8Encode = function(string) {
53			string = string.replace(/\x0d\x0a/g, "\x0a");
54			var output = "";
55			for (var n = 0; n < string.length; n++) {
56				var c = string.charCodeAt(n);
57				if (c < 128) {
58					output += String.fromCharCode(c);
59				} else if ((c > 127) && (c < 2048)) {
60					output += String.fromCharCode((c >> 6) | 192);
61					output += String.fromCharCode((c & 63) | 128);
62				} else {
63					output += String.fromCharCode((c >> 12) | 224);
64					output += String.fromCharCode(((c >> 6) & 63) | 128);
65					output += String.fromCharCode((c & 63) | 128);
66				}
67			}
68			return output;
69		};
70		
71		var uTF8Decode = function(input) {
72			var string = "";
73			var i = 0;
74			var c = c1 = c2 = 0;
75			while ( i < input.length ) {
76				c = input.charCodeAt(i);
77				if (c < 128) {
78					string += String.fromCharCode(c);
79					i++;
80				} else if ((c > 191) && (c < 224)) {
81					c2 = input.charCodeAt(i+1);
82					string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
83					i += 2;
84				} else {
85					c2 = input.charCodeAt(i+1);
86					c3 = input.charCodeAt(i+2);
87					string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
88					i += 3;
89				}
90			}
91			return string;
92		}
93		
94		$.extend({
95			base64Encode: function(input) {
96				var output = "";
97				var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
98				var i = 0;
99				input = uTF8Encode(input);
100				while (i < input.length) {
101					chr1 = input.charCodeAt(i++);
102					chr2 = input.charCodeAt(i++);
103					chr3 = input.charCodeAt(i++);
104					enc1 = chr1 >> 2;
105					enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
106					enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
107					enc4 = chr3 & 63;
108					if (isNaN(chr2)) {
109						enc3 = enc4 = 64;
110					} else if (isNaN(chr3)) {
111						enc4 = 64;
112					}
113					output = output + keyString.charAt(enc1) + keyString.charAt(enc2) + keyString.charAt(enc3) + keyString.charAt(enc4);
114				}
115				return output;
116			},
117			base64Decode: function(input) {
118				var output = "";
119				var chr1, chr2, chr3;
120				var enc1, enc2, enc3, enc4;
121				var i = 0;
122				input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
123				while (i < input.length) {
124					enc1 = keyString.indexOf(input.charAt(i++));
125					enc2 = keyString.indexOf(input.charAt(i++));
126					enc3 = keyString.indexOf(input.charAt(i++));
127					enc4 = keyString.indexOf(input.charAt(i++));
128					chr1 = (enc1 << 2) | (enc2 >> 4);
129					chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
130					chr3 = ((enc3 & 3) << 6) | enc4;
131					output = output + String.fromCharCode(chr1);
132					if (enc3 != 64) {
133						output = output + String.fromCharCode(chr2);
134					}
135					if (enc4 != 64) {
136						output = output + String.fromCharCode(chr3);
137					}
138				}
139				output = uTF8Decode(output);
140				return output;
141			}
142		});
143	})(jQuery);

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.