PDA

View Full Version : encode/decode



Savage
03-06-2006, 10:20 AM
Hi all.

I found this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>

<script type="text/javascript">

document.write(String.fromCharCode(72,69,76,76,79))

</script>

</body>
</html>

It simply produces this:

ABC

How can I encode some text (just like the ABC above) or javascript code into numbers?

Twey
03-06-2006, 11:38 AM
It simply produces this:

ABCWell, that's odd... it ought to produce "HELLO".

<script type="text/javascript">
function asciiEncode(s) {
var ret = "";
for(var i=0;i<s.length;i++) ret += s.charCodeAt(i) + ", ";
return ret;
}

window.alert(asciiEncode("some text"));
</script>
Or, as a bookmarklet:

javascript:window.alert((function(s){var ret="";for(var i=0;i<s.length;i++)ret+=s.charCodeAt(i)+(i==s.length-1?"":", ");return ret;})(window.prompt("Enter text to be converted:")));

jscheuer1
03-06-2006, 02:11 PM
http://centricle.com/tools/ascii-hex/