By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

based64 decoding in javascript

P: n/a
I need help implement based64 decoding in javascript: a function to
return a script that has been base64 encoded into a string (decoding in
client side). For encode, online base64 encoder tool was used.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>JavaScript Base64 Decoder</title>
<script type="text/javascript">
<!--
/*
//here is base64-encoded string:

PHNjcmlwdCB0eXBlPSJ0ZXh0L3Zic2NyaXB0Ij4gDQpGdW5jdG lvbiBlbmRlY3J5cHRfdmJzKGJvb2wpIA0KICAgIENvbnN0IGRp ZmYgPSAxIA0KICAgIERpbSBjaGFyLCBjb2RlLCBpLCB0ZW1wLC B0ZXh0IA0KICAgICAgICB0ZW1wID0gIiIgDQogICAgICAgIHRl eHQgPSBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgidGV4dCIpLn ZhbHVlIA0KICAgIEZvciBpID0gMSBUbyBMZW4odGV4dCkgDQog ICAgICAgIGNoYXIgPSBBc2MoTWlkKHRleHQsaSwxKSkgDQogIC AgICAgIElmIGJvb2wgVGhlbiANCiAgICAgICAgICAgIGNvZGUg PSBjaGFyICsgZGlmZiANCiAgICAgICAgRWxzZSANCiAgICAgIC AgICAgIGNvZGUgPSBjaGFyIC0gZGlmZiANCiAgICAgICAgRW5k IElmIA0KICAgICAgICB0ZW1wID0gdGVtcCAmIENocihjb2RlKS ANCiAgICBOZXh0IA0KICAgIGRvY3VtZW50LmdldEVsZW1lbnRC eUlkKCJ0ZXh0IikudmFsdWUgPSB0ZW1wIA0KRW5kIEZ1bmN0aW 9uIA0KPC9zY3JpcHQ+IA==

//Heres the decode function
function decode64(inp)
{
var out = ""; //This is the output
var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
var i = 0; //Position counter

// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
var base64test = /[^A-Za-z0-9\+\/\=]/g;

}
inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");

do { //Here.s the decode loop.

//Grab 4 bytes of encoded content.
enc1 = keyStr.indexOf(inp.charAt(i++));
enc2 = keyStr.indexOf(inp.charAt(i++));
enc3 = keyStr.indexOf(inp.charAt(i++));
enc4 = keyStr.indexOf(inp.charAt(i++));

//Heres the decode part. There.s really only one way to do it.
chr1 = (enc1 << 2) | (enc2 >4);
chr2 = ((enc2 & 15) << 4) | (enc3 >2);
chr3 = ((enc3 & 3) << 6) | enc4;

//Start to output decoded content
out = out + String.fromCharCode(chr1);

if (enc3 != 64) {
out = out + String.fromCharCode(chr2);
}
if (enc4 != 64) {
out = out + String.fromCharCode(chr3);
}

//now clean out the variables used
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";

} while (i < inp.length); //finish off the loop

//Now return the decoded values.
return out;
}

//-->

</script>
</head>

<body>

</body>
</html>

I'm not expert in javascript, so i dont know the correct method to
decode, the above decoder script is that i just found.
Another version:
this.decode = function()
{
var binary = new String();
var result = new String();
for(i = 0; i < this.string.length; i++)
{
for(j = 0; j < this.base64.length; j++)
{
if(this.string.charAt(i) == this.base64[j])
{
binary += String("000000" +
j.toString(2)).substring(j.toString(2).length);
}
}
}
for(i = 0; i < binary.length; i+=8)
{
var number = new Number();
var counter = new Number();
for(j = 0; j < binary.substring(i, i+8).length; j++)
{
for(k = 128; k >= 1; k-=(k/2))
{
if(binary.substring(i, i+8).charAt(counter++) ==
"1")
{
number += k;
}
}
}
result += String.fromCharCode(number);
}
return result;
}
}
thank you.
mistral

Sep 13 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
mistral wrote on 13 sep 2006 in comp.lang.javascript:
I need help implement based64 decoding in javascript: a function to
return a script that has been base64 encoded into a string (decoding
in client side). For encode, online base64 encoder tool was used.

Nearly 8 years ago:

<script type='text/javascript'>

// Free after: netscape.devs-javascript Martin Honnen - wo 28 okt 1998

var base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
base64 += 'abcdefghijklmnopqrstuvwxyz0123456789+/'
base64 = base64.split('')

function reverseBase64() {
var r = {};
for (var i = 0; i<64;i++)
r[base64[i]] = i;
return r;
}

var reversedBase64 = reverseBase64();
function decode (encStr) {
var charCodes = [];
var decStr = "";
for (var i = 0; i < encStr.length; i++)
charCodes[i] = reversedBase64[encStr.charAt(i)];
for (i = 0; i < encStr.length; i += 4) {
var bits24 = ( charCodes [i] & 0xFF ) << 18;
bits24 |= ( charCodes [i + 1] & 0xFF ) << 12;
bits24 |= ( charCodes [i + 2] & 0xFF ) << 6;
bits24 |= ( charCodes [i + 3] & 0xFF ) << 0;
decStr += String.fromCharCode((bits24 & 0xFF0000) >16);
if (charCodes[i + 2]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF00) > 8);
if (charCodes[i + 3]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF) > 0);
}
return decStr;
}

// beware of spurious new lines below
t =
'PHNjcmlwdCB0eXBlPSJ0ZXh0L3Zic2NyaXB0Ij4gDQpGdW5jd GlvbiBlbmRlY3J5cHRfdmJz
KGJvb2wpIA0KICAgIENvbnN0IGRpZmYgPSAxIA0KICAgIERpbS BjaGFyLCBjb2RlLCBpLCB0Z
W1wLCB0ZXh0IA0KICAgICAgICB0ZW1wID0gIiIgDQogICAgICA gIHRleHQgPSBkb2N1bWVudC
5nZXRFbGVtZW50QnlJZCgidGV4dCIpLnZhbHVlIA0KICAgIEZv ciBpID0gMSBUbyBMZW4odGV
4dCkgDQogICAgICAgIGNoYXIgPSBBc2MoTWlkKHRleHQsaSwxK SkgDQogICAgICAgIElmIGJv
b2wgVGhlbiANCiAgICAgICAgICAgIGNvZGUgPSBjaGFyICsgZG lmZiANCiAgICAgICAgRWxzZ
SANCiAgICAgICAgICAgIGNvZGUgPSBjaGFyIC0gZGlmZiANCiA gICAgICAgRW5kIElmIA0KIC
AgICAgICB0ZW1wID0gdGVtcCAmIENocihjb2RlKSANCiAgICBO ZXh0IA0KICAgIGRvY3VtZW5
0LmdldEVsZW1lbnRCeUlkKCJ0ZXh0IikudmFsdWUgPSB0ZW1wI A0KRW5kIEZ1bmN0aW9uIA0K
PC9zY3JpcHQ+IA=='
alert(decode(t))

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 13 '06 #2

P: n/a

Evertjan. писал(а):
mistral wrote on 13 sep 2006 in comp.lang.javascript:
mistral wrote on 13 sep 2006 in comp.lang.javascript:
I need help implement based64 decoding in javascript: a function to
return a script that has been base64 encoded into a string (decoding
in client side). For encode, online base64 encoder tool was used.

Nearly 8 years ago:

<script type='text/javascript'>

// Free after: netscape.devs-javascript Martin Honnen - wo 28 okt 1998
var base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
base64 += 'abcdefghijklmnopqrstuvwxyz0123456789+/'
base64 = base64.split('')

function reverseBase64() {
var r = {};
for (var i = 0; i<64;i++)
r[base64[i]] = i;
return r;
}

var reversedBase64 = reverseBase64();
function decode (encStr) {
var charCodes = [];
var decStr = "";
for (var i = 0; i < encStr.length; i++)
charCodes[i] = reversedBase64[encStr.charAt(i)];
for (i = 0; i < encStr.length; i += 4) {
var bits24 = ( charCodes [i] & 0xFF ) << 18;
bits24 |= ( charCodes [i + 1] & 0xFF ) << 12;
bits24 |= ( charCodes [i + 2] & 0xFF ) << 6;
bits24 |= ( charCodes [i + 3] & 0xFF ) << 0;
decStr += String.fromCharCode((bits24 & 0xFF0000) >16);
if (charCodes[i + 2]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF00) > 8);
if (charCodes[i + 3]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF) > 0);
}
return decStr;
}

// beware of spurious new lines below
t =
'PHNjcmlwdCB0eXBlPSJ0ZXh0L3Zic2NyaXB0Ij4gDQpGdW5jd GlvbiBlbmRlY3J5cHRfdmJz
KGJvb2wpIA0KICAgIENvbnN0IGRpZmYgPSAxIA0KICAgIERpbS BjaGFyLCBjb2RlLCBpLCB0Z
W1wLCB0ZXh0IA0KICAgICAgICB0ZW1wID0gIiIgDQogICAgICA gIHRleHQgPSBkb2N1bWVudC
5nZXRFbGVtZW50QnlJZCgidGV4dCIpLnZhbHVlIA0KICAgIEZv ciBpID0gMSBUbyBMZW4odGV
4dCkgDQogICAgICAgIGNoYXIgPSBBc2MoTWlkKHRleHQsaSwxK SkgDQogICAgICAgIElmIGJv
b2wgVGhlbiANCiAgICAgICAgICAgIGNvZGUgPSBjaGFyICsgZG lmZiANCiAgICAgICAgRWxzZ
SANCiAgICAgICAgICAgIGNvZGUgPSBjaGFyIC0gZGlmZiANCiA gICAgICAgRW5kIElmIA0KIC
AgICAgICB0ZW1wID0gdGVtcCAmIENocihjb2RlKSANCiAgICBO ZXh0IA0KICAgIGRvY3VtZW5
0LmdldEVsZW1lbnRCeUlkKCJ0ZXh0IikudmFsdWUgPSB0ZW1wI A0KRW5kIEZ1bmN0aW9uIA0K
PC9zY3JpcHQ+IA=='
alert(decode(t))

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
------------------------

Hi,

well, but it returned decoded content as popup alert, whereas I want
decoded script was executed in browser.

thanks
mistral

Sep 13 '06 #3

P: n/a
VK

mistral wrote:
I need help implement based64 decoding in javascript: a function to
return a script that has been base64 encoded into a string (decoding in
client side). For encode, online base64 encoder tool was used.
As an option:

/**
* The base64 encode/decode functions have been taken
* from 64 code from Tyler Akins -- http://rumkin.com
*/

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
keyStr+= "abcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >2;
enc2 = ((chr1 & 3) << 4) | (chr2 >4);
enc3 = ((chr2 & 15) << 2) | (chr3 >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);
} while (i < input.length);
return output;
}

function decode64(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
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 >4);
chr2 = ((enc2 & 15) << 4) | (enc3 >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);
}
} while (i < input.length);
return output;
}
/**
* End of borrowed code from
* Tyler Akins -- http://rumkin.com
*/

eval(decode64(myInput));
// that can be "interesting" things with your code on eval()
// depending on what is being executed. I wash my hands :-)

Also Mozilla has non-documented functions atob(string) to decode
and btoa(string) to encode. They work much faster then custom
functions but can handle only relatively small strings (because
they originally were made for encoded keys exchange).

Sep 13 '06 #4

P: n/a
mistral wrote on 13 sep 2006 in comp.lang.javascript:
well, but it returned decoded content as popup alert, whereas I want
decoded script was executed in browser.
So you change that part of the code?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 13 '06 #5

P: n/a

VK писал(а):
mistral wrote:
I need help implement based64 decoding in javascript: a function to
return a script that has been base64 encoded into a string (decoding in
client side). For encode, online base64 encoder tool was used.

As an option:

/**
* The base64 encode/decode functions have been taken
* from 64 code from Tyler Akins -- http://rumkin.com
*/
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
keyStr+= "abcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >2;
enc2 = ((chr1 & 3) << 4) | (chr2 >4);
enc3 = ((chr2 & 15) << 2) | (chr3 >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);
} while (i < input.length);
return output;

}
function decode64(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
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 >4);
chr2 = ((enc2 & 15) << 4) | (enc3 >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);
}
} while (i < input.length);
return output;

}
/**
* End of borrowed code from
* Tyler Akins -- http://rumkin.com
*/

eval(decode64(myInput));
// that can be "interesting" things with your code on eval()
// depending on what is being executed. I wash my hands :-)
Also Mozilla has non-documented functions atob(string) to decode
and btoa(string) to encode. They work much faster then custom
functions but can handle only relatively small strings (because
they originally were made for encoded keys exchange).
--------------------

can confirm, that this not work also.. It's not as easy as it looks.
Where is input for encoded string?

mistral

Sep 13 '06 #6

P: n/a
VK

mistral wrote:
can confirm, that this not work also.. It's not as easy as it looks.
Where is input for encoded string?
Oh, that's easy.

You are going to the official group FAQ page at
<http://www.jibbering.com/faq>. There is a list of online sources and
at least one good book to read. You can start from the basics and make
a simple HTML form to input text and a button to encode/decode it on
click. After you show your initial attempt, people around will gladly
help you to tune it up.

On the second stage you can learn IXMLHTTPRequest/XMLHttpRequest
principles (do not hesitate to ask here!) to retrieve/send some data
from/to server. After you make your first ajaxoid, people around will
gladly help you to tune it up.

For the first stage you should not spend more then an hour (having some
basic knowledge of JavaScript). So if you rush, you still can catch me
today with your first version.

;-)
:-|

Sep 13 '06 #7

P: n/a

Evertjan. писал(а):
mistral wrote on 13 sep 2006 in comp.lang.javascript:
well, but it returned decoded content as popup alert, whereas I want
decoded script was executed in browser.
So you change that part of the code?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
----------

I found one my error: the code has been encrypted to include the
<scripttags with it, this makes it difficult to run, because any code
trying to run it will already be in script tags and i can't have
embedded script tags.
I also removed superfluous alert, butl can no fire up script still. I
think endcoded part must goes somewhere at the top, that the rest code
can read it, then decode and execute. I know that in VBA macro, the
encoded code goes first.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<title</title>
<head>
<script type='text/javascript'>

// Free after: netscape.devs-javascript Martin Honnen - wo 28 okt 1998
var base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
base64 += 'abcdefghijklmnopqrstuvwxyz0123456789+/'
base64 = base64.split('')
function reverseBase64() {
var r = {};
for (var i = 0; i<64;i++)
r[base64[i]] = i;
return r;

}
var reversedBase64 = reverseBase64();

function decode (encStr) {
var charCodes = [];
var decStr = "";
for (var i = 0; i < encStr.length; i++)
charCodes[i] = reversedBase64[encStr.charAt(i)];
for (i = 0; i < encStr.length; i += 4) {
var bits24 = ( charCodes [i] & 0xFF ) << 18;
bits24 |= ( charCodes [i + 1] & 0xFF ) << 12;
bits24 |= ( charCodes [i + 2] & 0xFF ) << 6;
bits24 |= ( charCodes [i + 3] & 0xFF ) << 0;
decStr += String.fromCharCode((bits24 & 0xFF0000) >16);
if (charCodes[i + 2]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF00) > 8);
if (charCodes[i + 3]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF) > 0);
}
return decStr;

}
reverseBase64('PCEtLWhpZGUgZnJvbSBvbGQgYnJvd3NlcnM NCmFsZXJ0KCdXZWxjb21lIHRvIG15IFdlYiBTaXRlIScpOw0KL y8tLT4NCg=='
)

</script
</head>

<body>
</body>
</html>

Sep 13 '06 #8

P: n/a
mistral wrote on 14 sep 2006 in comp.lang.javascript:
I found one my error: the code has been encrypted to include the
<scripttags with it, this makes it difficult to run, because any code
trying to run it will already be in script tags and i can't have
embedded script tags.
Seems you have no scripting experience at all.

x = x.replace(/(<script[^>]*>)|(<\/script>)/g,'')

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 14 '06 #9

P: n/a

Evertjan. писал(а):
mistral wrote on 14 sep 2006 in comp.lang.javascript:
I found one my error: the code has been encrypted to include the
<scripttags with it, this makes it difficult to run, because any code
trying to run it will already be in script tags and i can't have
embedded script tags.

Seems you have no scripting experience at all.

x = x.replace(/(<script[^>]*>)|(<\/script>)/g,'')

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
----------------
Seems you have no scripting experience at all.
no, i have mainly in VBA..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<title</title>
<head>
<script type='text/javascript'>
// Free after: netscape.devs-javascript Martin Honnen - wo 28 okt 1998
var base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
base64 += 'abcdefghijklmnopqrstuvwxyz0123456789+/'
base64 = base64.split('')
function reverseBase64() {
var r = {};
for (var i = 0; i<64;i++)
r[base64[i]] = i;
return r;

}
var reversedBase64 = reverseBase64();

function decode (encStr) {
var charCodes = [];
var decStr = "";
for (var i = 0; i < encStr.length; i++)
charCodes[i] = reversedBase64[encStr.charAt(i)];
for (i = 0; i < encStr.length; i += 4) {
var bits24 = ( charCodes [i] & 0xFF ) << 18;
bits24 |= ( charCodes [i + 1] & 0xFF ) << 12;
bits24 |= ( charCodes [i + 2] & 0xFF ) << 6;
bits24 |= ( charCodes [i + 3] & 0xFF ) << 0;
decStr += String.fromCharCode((bits24 & 0xFF0000) >16);
if (charCodes[i + 2]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF00) > 8);
if (charCodes[i + 3]) // check for padding character =
decStr += String.fromCharCode((bits24 & 0xFF) > 0);
}
return decStr;

}
reverseBase64('PCEtLWhpZGUgZnJvbSBvbGQgYnJvd3NlcnM NCmFsZXJ0KCdXZWxjb21lIHRv*IG15IFdlYiBTaXRlIScpOw0 KLy8tLT4NCg=='

)

</script
</head
<body
</body
</html>

Sep 14 '06 #10

P: n/a

Evertjan. писал(а):
mistral wrote on 14 sep 2006 in comp.lang.javascript:
I found one my error: the code has been encrypted to include the
<scripttags with it, this makes it difficult to run, because any code
trying to run it will already be in script tags and i can't have
embedded script tags.

Seems you have no scripting experience at all.

x = x.replace(/(<script[^>]*>)|(<\/script>)/g,'')

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
-----------------------------
Here is how it should be:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<titleDecoder</title>

<script id="mydataString" type="text/jscript">
</script>

<script type='text/javascript'>

var base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
base64 += 'abcdefghijklmnopqrstuvwxyz0123456789+/';
base64 = base64.split('');
function reverseBase64() {
var r = {};
for (var i = 0; i<64;i++){
r[base64[i]] = i;
}
return r;
}
var reversedBase64 = reverseBase64();

function decode (encStr) {
var charCodes = [];
var decStr = "";
for (var i = 0; i < encStr.length; i++){
charCodes[i] = reversedBase64[encStr.charAt(i)];
}
for (i = 0; i < encStr.length; i += 4) {
var bits24 = ( charCodes [i] & 0xFF ) << 18;
bits24 |= ( charCodes [i + 1] & 0xFF ) << 12;
bits24 |= ( charCodes [i + 2] & 0xFF ) << 6;
bits24 |= ( charCodes [i + 3] & 0xFF ) << 0;
decStr += String.fromCharCode((bits24 & 0xFF0000) >16);

// check for padding character =
if (charCodes[i + 2]) {
decStr += String.fromCharCode((bits24 & 0xFF00) > 8);
}

// check for padding character =
if (charCodes[i + 3]) {
decStr += String.fromCharCode((bits24 & 0xFF) > 0);
}
}
return decStr;

}

//base64 encoded script
t =
'PCEtLWhpZGUgZnJvbSBvbGQgYnJvd3NlcnMNCmFsZXJ0KCdXZ Wxjb21lIHRvIG15IFdlYiBTaXRlIScpOw0KLy8tLT4NCg==';

mydataString.text = decode(t);
</script>
</head>

<body>
</body>
</html>

Sep 15 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.