473,387 Members | 1,291 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

based64 decoding in 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.
<!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
10 6167
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

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
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
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

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
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

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
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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: steve | last post by:
Hi, I am opening a stream that is UTF encoded. I use fgetc to read the stream- which is binary safe. I add every character read to a string. But when I look at the stream, I see some...
1
by: Matthias Stern | last post by:
Hello! I've got a Javascript-PHP encoding problem. (1) Here is the short version: ============================== I'm sending a form textfield via Javascript(!) as URL parameter (GET)...
27
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image...
0
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the...
0
by: R L Vandaveer | last post by:
I am having an interesting and rather frustrating issue with the encoding/decoding of parameters with the ASP.NET runtime. What I am doing isn't exactly revolutionary so hopefully someone has an...
5
by: Peter Jansson | last post by:
Hello group, The following code is an attempt to perform URL-decoding of URL-encoded string. Note that std::istringstream is used within the switch, within the loop. Three main issues have been...
8
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I protect a webpage in javascript?...
9
by: KWSW | last post by:
Having settled the huffman encoding/decoding and channel modeling(thanks to the previous part on bitwise operation), the last part would be hamming encoding/decoding. Did some research as usual on...
0
by: Michele | last post by:
Hi there, I'm using a python script in conjunction with a JPype, to run java classes. So, here's the code: from jpype import * import os import random import math import sys
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.