Created
July 31, 2015 05:18
-
-
Save JavaScript-Packer/415d92f0448af48b8c5b to your computer and use it in GitHub Desktop.
Base64 encoder with UTF-8 encoding - Base64 Button function for http://www.whak.ca/packer/LZW(HAK).htm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function b2a(r) { | |
function utf(r) { | |
var t, e, o; | |
for (r = r.replace(/\r\n/g, "\n"), t = "", e = 0; e < r.length; e++) o = r.charCodeAt(e), | |
128 > o ? t += String.fromCharCode(o) :o > 127 && 2048 > o ? (t += String.fromCharCode(192 | o >> 6), | |
t += String.fromCharCode(128 | 63 & o)) :(t += String.fromCharCode(224 | o >> 12), | |
t += String.fromCharCode(128 | 63 & o >> 6), t += String.fromCharCode(128 | 63 & o)); | |
return t; | |
} | |
var t, a, h, e, o, c, n = "", C = 0, i = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
for (r = utf(r); C < r.length; ) t = r.charCodeAt(C++), a = r.charCodeAt(C++), h = r.charCodeAt(C++), | |
e = t >> 2, t = (3 & t) << 4 | a >> 4, o = (15 & a) << 2 | h >> 6, c = 63 & h, isNaN(a) ? o = c = 64 :isNaN(h) && (c = 64), | |
n = n + i.charAt(e) + i.charAt(t) + i.charAt(o) + i.charAt(c); | |
return n; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment