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