You are on page 1of 3

/* Start - Copyright (c) 2000 by Robert Graham (RobertGraham.

com) */
//function myBase64Encode(base64s) {var base64r="";var base64i=0;var base64x=0;v
ar base64l=0;var base64o=0;for(base64i=0;base64i<base64s.length;base64i++){base6
4o=base64s.charCodeAt(base64i);switch(base64i%3){case 0:{base64x=(base64o&0xFC)>
>2;base64l=base64o&0x03;break}case 1:{base64x=(base64l<<4)|((base64o&0xF0)>>4);b
ase64l=base64o&0x0F;break}case 2:{base64x=(base64l<<2)|((base64o&0xC0)>>6);base6
4l=(base64o&0x3F);break}}base64r=base64r+base64ToAscii(base64x);if((base64i%3)==
2){base64r=base64r+base64ToAscii(base64l)}}switch(base64s.length%3){case 0:{brea
k}case 1:{base64l=base64l<<4;base64r=base64r+base64ToAscii(base64l);base64r=base
64r+"==";break}case 2:{base64l=base64l<<2;base64r=base64r+base64ToAscii(base64l)
;base64r=base64r+"=";break}}return base64r}function base64ToAscii(base64c){var t
heChar=0;if(0<=base64c&&base64c<=25){theChar=String.fromCharCode(base64c+65)}els
e if(26<=base64c&&base64c<=51){theChar=String.fromCharCode(base64c-26+97)}else i
f(52<=base64c&&base64c<=61){theChar=String.fromCharCode(base64c-52+48)}else if(b
ase64c==62){theChar='+'}else if(base64c==63){theChar='/'}else{theChar=String.fro
mCharCode(0xFF)}return theChar}
//myBase64Encode(String) return String
//function myBase64Decode(base64s,base64b){var base64r="";var base64i=0;var base
64x;var base64g=0;var base64t=-1;var base64v;var base64c;for(base64i=0;base64i<b
ase64s.length;base64i++){base64c=base64s.charAt(base64i); if('A'<=base64c&&base6
4c<='Z'){base64x=base64s.charCodeAt(base64i)-65}else if('a'<=base64c&&base64c<='
z'){base64x=base64s.charCodeAt(base64i)-97+26} else if('0'<=base64c&&base64c<='9
'){base64x=base64s.charCodeAt(base64i)-48+52}else if(base64c=='+'){base64x=62}el
se if(base64c=='/'){base64x=63}else continue;base64t++; switch(base64t%4){case 0
:{base64g=base64x;continue}case 1:{base64v=(base64g<<2)|(base64x>>4);base64g=bas
e64x&0x0F;break}case 2:{base64v=(base64g<<4)|(base64x>>2);base64g=base64x&0x03;b
reak}case 3:{base64v=(base64g<<6)|(base64x>>0);base64g=base64x&0x00;break}}if(!b
ase64b&&(base64v<32||base64v>126)&&(base64v!=0x0d)&&(base64v!=0x0a)){base64r=bas
e64r+"<";base64r=base64r+"0123456789ABCDEF".charAt((base64v/16)&0x0F);base64r=ba
se64r+"0123456789ABCDEF".charAt((base64v/1)&0x0F);base64r=base64r+">"}else{base6
4r=base64r+String.fromCharCode(base64v)}}return base64r.toString()}
//myBase64Decode(String,true) return String
/* End - Copyright (c) 2000 by Robert Graham (RobertGraham.com) */
/* START - CopyRight: Dr Alexander J Turner - all rights reserved. */
function Base64() {
this.maxLineLength = 76;
this.base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012
3456789+/";
this.decode = function(encStr) {
var base64charToInt = {};
for (var i = 0; i < 64; i++) base64charToInt[this.base64chars.substr(i,1
)] = i;
encStr = encStr.replace(/\s+/g, "");
var decStr = "";
var decArray=new Array();
var linelen = 0
var el=encStr.length;
var bits24;
for (var i = 0; i < el; i += 4) {
bits24 = ( base64charToInt[encStr.charAt(i)] & 0xFF ) << 18;
bits24 |= ( base64charToInt[encStr.charAt(i+1)] & 0xFF ) << 12;
bits24 |= ( base64charToInt[encStr.charAt(i+2)] & 0xFF ) << 6;
bits24 |= ( base64charToInt[encStr.charAt(i+3)] & 0xFF ) << 0;
decStr += String.fromCharCode((bits24 & 0xFF0000) >> 16);
if (encStr.charAt(i + 2) != '=') // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF00) >> 8);
if (encStr.charAt(i + 3) != '=') // check for padding character =

decStr += String.fromCharCode((bits24 &


if(decStr.length>1024)
{
decArray.push(decStr);
decStr='';
}

0xFF) >> 0);

}
if(decStr.length>0)
{
decArray.push(decStr);
}
var ar2=new Array();
for(;decArray.length>1;)
{
var l=decArray.length;
for(var c=0;c<l;c+=2)
{
if(c+1==l)
{
ar2.push(decArray[c]);
}
else
{
ar2.push(''+decArray[c]+decArray[c+1]);
}
}
decArray=ar2;
ar2=new Array();
}
return decArray[0];
}
this.encode = function(decStr)
{
var encArray=new Array();
var bits, dual, i = 0, encOut = "";
var linelen = 0;
var encOut='';
while(decStr.length >= i + 3){
bits =
(decStr.charCodeAt(i++) & 0xff) <<16 |
(decStr.charCodeAt(i++) & 0xff) <<8 |
decStr.charCodeAt(i++) & 0xff;
encOut +=
this.base64chars.charAt((bits & 0x00fc0000) >>18) +
this.base64chars.charAt((bits & 0x0003f000) >>12) +
this.base64chars.charAt((bits & 0x00000fc0) >> 6) +
this.base64chars.charAt((bits & 0x0000003f));
linelen += 4;
if (linelen>this.maxLineLength-3) {
encOut += "\n";
encArray.push(encOut);
encOut='';
linelen = 0;
}
}
if(decStr.length -i > 0 && decStr.length -i < 3) {
dual = Boolean(decStr.length -i -1);
bits =
((decStr.charCodeAt(i++) & 0xff) <<16) |

(dual ? (decStr.charCodeAt(i) & 0xff) <<8 :


encOut +=
this.base64chars.charAt((bits & 0x00fc0000)
this.base64chars.charAt((bits & 0x0003f000)
(dual ? this.base64chars.charAt((bits

0);
>>18) +
>>12) +
& 0x00000fc0) >>6) :

'=') +
'=';
}
encArray.push(encOut);
// this loop progressive concatonates the
// array elements entil there is only one
var ar2=new Array();
for(;encArray.length>1;)
{
var l=encArray.length;
for(var c=0;c<l;c+=2)
{
if(c+1==l)
{
ar2.push(encArray[c]);
}
else
{
ar2.push(''+encArray[c]+encArray[c+1]);
}
}
encArray=ar2;
ar2=new Array();
}
return encArray[0];
}
}
/* END - CopyRight: Dr Alexander J Turner - all rights reserved. */
var myBase64=new Base64();
function myBase64Encode(base64s) {
if ("!"+base64s=="!") { return "" }
return myBase64.encode(base64s);
}
function myBase64Decode(base64s,base64b) {
if ("!"+base64s=="!") { return "" }
return myBase64.decode(base64s);
}