SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Decoding

    I took a test in my A+ repair class the other day and got a 100 on it. Curious to look at the coding as I love web design and know a good amount, I peeked at the source code. After much much frustration I decided to ask some people how this works. I can see the answers are set with the variables near the beginning, problem is it doesn't really match the answers that are correct. So I am amazingly curious as to how it works. The answers are:

    1. B
    2. A
    3. B
    4. A
    5. D
    6. C
    7. C
    8. D
    9. B
    10. A
    11. B
    12. B
    13. C
    14. B
    15. B
    16. A
    17. A
    18. D
    19. C
    20. C

    And the whole pages code is: (Would not work when posting here so i uploaded in a notepad file)

    mediafire.com/?utagmnmkzyz

    Thanks everyone!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It uses a simple formula to translate some character codes into the actual string which is the answer. This bit:
    Code javascript:
    function TranslateAnswer(s, answerIndex)
        {
            var    value;
            var    newString;
            var    code;
            var    i;
     
            value = (answerIndex % 31) + 1;
            newString = "";
            for (i=0; i < s.length; i += 2) {
                code = parseInt(s.substring(i, i + 2), 16);
                newString += String.fromCharCode(code ^ value);
            }
     
            return(newString);
        }
     
    function ScoreAnswer(answerIndex, responseText, pointsPossible)
        {
            var answerText = TranslateAnswer(ansMap[answerIndex], answerIndex);
    // ... irrelevant stuff
    }
    The ansMap answers are all in hexadecimal notation, which is turned into an integer (parseInt bit) and then that is turned into a different number and the fromCharCode function turns that number into an actual character (from Unicode character codes).

    To generate the answers, the reverse procedure was applied, probably by a server-side script.


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
  •