Javascript| Code
<SCRIPT>
var base64encodechars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64decodechars = new Array (
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,,-62, 1,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,-1,-1,-1,-1,-1,-1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,-1,-1,-1,-1,-1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,-1,-1,-1,-1,-1);
function Base64Encode (str) {
var out, I, Len;
var C1, C2, C3;
len = str.length;
i = 0;
out = "";
while (I < Len) {
C1 = Str.charcodeat (i++) & 0xFF;
if (i = = len)
{
Out + = Base64encodechars.charat (C1 >> 2);
Out + = Base64encodechars.charat ((C1 & 0x3) << 4);
Out + = "= =";
Break
}
C2 = Str.charcodeat (i++);
if (i = = len)
{
Out + = Base64encodechars.charat (C1 >> 2);
Out + + Base64encodechars.charat ((C1 & 0x3) << 4) | ((C2 & 0xF0) >> 4));
Out + = Base64encodechars.charat ((C2 & 0xF) << 2);
Out + = "=";
Break
}
C3 = Str.charcodeat (i++);
Out + = Base64encodechars.charat (C1 >> 2);
Out + + Base64encodechars.charat ((C1 & 0x3) << 4) | ((C2 & 0xF0) >> 4));
Out + + Base64encodechars.charat ((C2 & 0xF) << 2) | ((C3 & 0xc0) >>6));
Out + = Base64encodechars.charat (C3 & 0x3F);
}
return out;
}
function Base64decode (str) {
var C1, C2, C3, C4;
var i, Len, out;
len = str.length;
i = 0;
out = "";
while (I < Len) {
* C1 * *
do {
C1 = Base64decodechars[str.charcodeat (i++) & 0xFF];
while (I < len && C1 = = 1);
if (C1 = = 1)
Break
* C2 * *
do {
C2 = Base64decodechars[str.charcodeat (i++) & 0xFF];
while (i < len && C2 = = 1);
if (C2 = = 1)
Break
Out + + string.fromcharcode (C1 << 2) | ((C2 & 0x30) >> 4));
* C3 * *
do {
C3 = Str.charcodeat (i++) & 0xFF;
if (C3 = 61)
return out;
C3 = Base64decodechars[c3];
while (I < Len && C3 = = 1);
if (C3 = = 1)
Break
Out + + String.fromCharCode ((C2 & 0XF) << 4) | ((C3 & 0x3c) >> 2));
* C4 * *
do {
C4 = str.charcodeat (i++) & 0xFF;
if (C4 = 61)
return out;
C4 = base64decodechars[c4];
while (i < len && C4 = = 1);
if (C4 = = 1)
Break
Out + = String.fromCharCode ((C3 & 0x03) << 6) | c4);
}
return out;
}
Alert (Base64Encode ("?"))
</script>