Js-base64 Encryption Instance:
<! doctype html> Base64,js
/**** base64 encode / decode** @author * @date 2010-04-26* @email **/ function base64 () { // private property_keystr = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/="; // public method for encodingthis.encode = function (Input) {var output = "";var chr1, chr2, chr3, enc1, enc2, enc3, enc4; Var i = 0;input = _utf8_encode (Input);while (i < input.length) {chr1 = input.charcodeat (i++); Chr2 = input.charcodeat (i++);chr3 = Input.charcodeat (i++);enc1 = chr1 >> 2;enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);enc3 = ((chr2 & 15) &NBSP;<<&NBSP;2) | (CHR3&NBsp;>> 6);enc4 = chr3 & 63;if (IsNaN (CHR2)) {enc3 = enc4 = 64;} else if (IsNaN (CHR3)) {enc4 = 64;} Output = output +_keystr.charat (ENC1) + _keystr.charat (ENC2) +_keystr.charat ( ENC3) + _keystr.charat (ENC4);} Return output;} // public method for decodingthis.decode = function (Input) {var output = ""; var chr1, chr2, chr3;var enc1, enc2, enc3, enc4 ; Var i = 0;input = input.replace (/[^a-za-z0-9\+\/\=]/g, "");while (i < input.length) {enc1 = _keystr.indexof (Input.charat (i++)); enc2 = _ Keystr.indexof (Input.charat (i++)); Enc3 = _keystr.indexof (Input.charat (i++)); enc4 = _ Keystr.indexof (Input.charat (i++));chr1 = (enc1 << 2) | (ENC2&NBSP;>>&NBSP;4);chr2 = ((enc2 & 15) << 4) | (enc3 >> &NBSP;2);chr3 = ((enc3 & 3) << 6) | enc4;output = Output + string.fromcharcode (CHR1);if (enc3 != 64) {output = output + string.fromcharcode (CHR2);} if (enc4 != 64) {output = output + string.fromcharcode (CHR3);}} Output = _utf8_decode (output); return output;} // private method for UTF-8 encoding_utf8_encode = function ( String) {string = string.replace (/\r\n/g, "\ n");var utftext = "";for (Var n = 0; n < string.length; n++) {var c = String.charcodeat (n);if (c < 128) {utftext += string.fromcharcode (c); else if ((c > 127) && (c < 2048)) {utftext += string.fromcharcode ((c >> 6) | 192); Utftext += string.fromcharcode ((c & 63) | 128);} else {utftext += string.fromcharcode ((c >> 12) | 224); Utftext += string.fromcharcode (((c >> 6) & 63) | 128);utftext += string.fromcharcode ((c & 63) | 128);} }return utftext;} // private method for UTF-8 decoding_utf8_decode = function ( Utftext) {var string = ";var i = 0;var c = c1 = c2 = 0;while ( i < utftext.length ) {c = Utftext.charcodeat (i);if (c < 128) {string += string.fromcharcode (c); i++;} else if ((c > 191) && (c < 224) {c2 = utftext.charcodeat (i+1); String += string.fromcharcode ((c & 31) ( << 6) | (c2 & 63)); i += 2;} else {c2 = utftext.charcodeat (i+1); C3 = utftext.charcodeat (i+2); string += string.fromcharcode ((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3;}} return string;}}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/74/7F/wKiom1YfFzSgcaQpAAGfZLm3Ar4162.jpg "title=" aa.png "alt=" Wkiom1yffzsgcaqpaagfzlm3ar4162.jpg "/>
This article is from the "Wennuanyiran" blog, make sure to keep this source http://dingzhaoqiang.blog.51cto.com/5601059/1703095
JS-BASE64 encryption