/*! * jquery.base64.js 0.1 - https://github.com/yckart/jquery.base64.js * base64 en & -decoding * * copyright (c) 2012 yannick albert (http://yckart.com) * licensed under the mit license (http://www.opensource.org/licenses/mit-license.php). * 2013/02/10 **/ ;(function($){ $.base64 = $.fn.base64 = function (dir, input) { var publ = {}, self = this, b64 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/="; // http://phpjs.org/functions/base64_encode/ publ.encode = function (data) { data = !(self instanceof $) ? data : self.is(':input') ? self.val() : self.text(); data = unescape(encodeuricomponent( data )); if (data === '') return; var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc = "", tmp_arr = []; if (!data) return data; do { // pack three octets into four hexets o1 = data.charcodeat(i++); o2 = data.charcodeat(i++); o3 = data.charcodeat(i++); bits = o1 << 16 | o2 << 8 | o3; h1 = bits >> 18 & 0x3f; h2 = bits >> 12 & 0x3f; h3 = bits >> 6 & 0x3f; h4 = bits & 0x3f; // use hexets to index into b64, and append result to encoded string tmp_arr[ac++] = b64.charat(h1) + b64.charat(h2) + b64.charat(h3) + b64.charat(h4); } while (i < data.length); enc = tmp_arr.join(''); var r = data.length % 3; return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); }; // http://phpjs.org/functions/base64_decode/ publ.decode = function (data) { data = !(self instanceof $) ? data : self.is(':input') ? self.val() : self.text(); var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = []; if (!data) return data; data += ''; do { // unpack four hexets into three octets using index points in b64 h1 = b64.indexof(data.charat(i++)); h2 = b64.indexof(data.charat(i++)); h3 = b64.indexof(data.charat(i++)); h4 = b64.indexof(data.charat(i++)); bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; o1 = bits >> 16 & 0xff; o2 = bits >> 8 & 0xff; o3 = bits & 0xff; if (h3 == 64) { tmp_arr[ac++] = string.fromcharcode(o1); } else if (h4 == 64) { tmp_arr[ac++] = string.fromcharcode(o1, o2); } else { tmp_arr[ac++] = string.fromcharcode(o1, o2, o3); } } while (i < data.length); dec = tmp_arr.join(''); return decodeuricomponent(escape( dec )); }; return input ? publ[dir](input) : dir ? null : publ; }; }(jquery));