Results 1 to 3 of 3

Thread: encode/decode

  1. #1
    Join Date
    Jan 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default encode/decode

    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?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It simply produces this:

    ABC
    Well, that's odd... it ought to produce "HELLO".
    Code:
    <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:
    Code:
    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:")));
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,004
    Thanks
    44
    Thanked 3,203 Times in 3,165 Posts
    Blog Entries
    12

    Default

    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •