"No exceptional circumstances whatsoever, whether a state of war or a threat of war, internal political instability, or any other public emergency, may be invoked as a justification of torture." -- U.N. Convention Against Torture
Published by: Blind-Summit, on 2007-08-28 02:52:03
I had completed this challenge a long time ago - but never saved the source code for it. I have been ask a few times for help on this mission, and I would like to try and help you get started.
So the mission requires you to take the 10 scrambled words, unscramble them and then submit the answers back in a list within 20 seconds. The words are taken from a wordlist containing around 1200 words. The concept is pretty simple - it's a case of taking the scrambled words - one by one, and checking them for a match against the wordlist.
The problem comes in the comparison. Programatically - you cannot simply compare the scrambled word against each line of the wordlist and look for a match. You are going to need some sort of code to unscramble and check the list.
I write all of my answers in PHP, but you can probably us similar functions if you code in python / c++ etc. My first attempt was crude, but it worked. I checked string lengths and counted up letters. Nothing worth shouting about!
The first thing you will need to do is to get a copy of the wordlist, and save this to your webserver. Use a function like fopen() to open this file. Read in each line and save it into an array. Next, you will need some sort of form to take the scrambled words. I used an html textarea. Once the form was submitted, my code took the contents of the textarea and split it up word by word. I needed to clean up the scrambled words here to remove extra spaces and the # character. I then put the scrambled words into another array.
So here comes the smart bit - how do you compare the jumbled up word against the wordlist? As I said before, my first attempt was very crude - so I won't try and take you along this path.
I thought about hashing the words and comparing these values - but that won't work as the words would need to be identical for the hashes to match. What about numbering the letters from 1 to 26? This was closer to my final version - but if a=1 and b=2, we could get a match if we had "aa" or "b" because they both equal 2. I decided to use a power for each letter. a=1 b=2 c=4 d=8 and so on. Because the wordlist was quite short, and the words were also short - we could assume that the chances of getting answers where d and aaaaaaaa would produce problems. I used a string length check to make sure.
Another method that I saw someone on the forum mention was to take the scrambled words and rearrange the letters alphabetically. If this was then checked agains the wordlist, where again the words were re-aranged aphabetically - we would get a match without the need for numbers or hashes. I went with my version because I like numbers.
I then looped through each of my scrambled words and chacked them against the wordlist (also converted to a powered value). If I got a match - I printed the wordlist word to the screen. Because each lettter had a unique value - it didn't matter about the order of the letters, and as I said - the chances of having a match because of several letters having the same value of another letter were almost zero.
The process took around 4 or 5 seconds from copying the scrambled words from the HTS page, into my PHP script and then back. Plenty of time.
So just to summarise.
Read in the wordlist to an array
Read in the scrambled words.
Give the scrambled words a value
Give the wordlist words a value
Check the numbers against each other
Print the word if you have a match.
HackThisSite is the collective work of the HackThisSite staff, licensed under a CC BY-NC license.
We ask that you inform us upon sharing or distributing.