"The greatest power of the mass media is the power to ignore. The worst thing about this power is that you may not even know you're using it." --Sam Smith
So the objective here is to find the encoded Morse from the randomly generated image, then decode it to numbers and letters – which is going to be our answer.
There are three steps to this problem.
1) Get positions for white pixels
2) Convert information from step 1 to ASCII code
3) Decode the Morse
Step 1: Get positions for white pixels
Before we start the first step there are some things we want to keep in mind. Firstly row 1 goes from 0 – 99, row 2 goes from 100 – 199, row 3 goes from 200 – 299 and so on. Secondly go and download five (or how many you want) randomly generated pictures from challenge 2. Open it up with some image editor and take a look at the width and the height. What do you notice for all of the images?
spoiler:
Width always equals 100
Height always equals 30
Keep that in mind
Now after we have gone over that let us dive into the first step of the solution. First of all there is a very class in VB 2008 called ArrayList. It could be a great tool because with the ArrayList class, “you can add new items to a list, insert items inside a list, arrange items of a list, check the existence of an item in a list, remove an item from the list, inquire about the list, or destroy the list.” “The main problem of traditional arrays is that their size is fixed by the number you specify when declaring the array variable: you cannot add items beyond the specified dimension. Another limitation is that you cannot insert an item inside the list.” (http://www.functionx.com/vbnet/collections/arraylist.htm)
Now what we would need to do is find a way to go through the randomly generated image from left to right starting from the uppermost left corner.
spoiler:
Perhaps, we could make a nested loop in order to accomplish the goal? Also remember the width and the height of the image? Well that is what you are going to be using to traverse from left to right and get the white pixels.
Now that we know how to go from left to right we can do that and also have a conditional statement that checks to see if any of the pixels are white. Once it is white you would want to take its X-position remember that.
One of the other REALLY IMPORTANT things to remember is that ONLY the first white dot’s position stays the same for other once you would have to subtract. For example if the very first dot has a position of 15 then you would leave it as 15 and that would be the ONLY one. And for instance if the second white dot has a position of 99 then you would say 99 – 15.
Now also remember that second row does not go from 0 – 99 it goes from 100 – 199 and third one goes from 200 -299 and so on.
spoiler:
In order to solve that problem easily you could make an external function which for example is called convert_row. It would take 2 arguments, first being the current x position and second being the row number. That function would multiply row number by 100 then add the x position to it and return the result. The value being returned would be the position of the white dot corresponding to each row.
Now once you loop through the image and get position for the white dots you would need to save them somewhere as you go along.
Here is where the ArrayList comes in handy :)
Step 2: Convert information from step 1 to ASCII code
I think this is one of the shortest steps since it is only a loop. In this step we only need to get the numbers representing positions, perform subtraction to get the ASCII codes and then convert them into ASCII characters.
Now think about it… if you have the position in some kind of array then you know that the order is correct meaning the first element of the array represents the first white dot’s x-position, second one represents the second white dot’s position and so on.
spoiler:
Knowing that we can loop through the array and in the array we can have a conditional statement which will take care of the first position being untouched. So for example if it is 65 it will be untouched as in no other position will be subtracted from it BECAUSE it is the FIRST position and there are not other position before it. Hence we would only convert the first position into a ASCII character by using the Chr() function without subtracting anything from it. Now when we are done with that condition next time loop goes through it will get to the second position and for that one we would need to subtract the position before it from it. And only then convert it to an ASCII character. The formula would look like this chr(your_array(index) – your_array(index - 1)).
I would also suggest that you make a string called encoded_answer (name does not matter) and as you are finding each ASCII character you concatenate the found one to the encoded _answer. For concatenation you could use String.concat(string1, string2) or simply a + sign.
Step 3: Decode the Morse
In my opinion the third step is one of the most annoying once since it has a lot of writing and no logic. Since the encoded_answer above has the encoded Morse code we take a look at it and see that each Morse code is separated by an empty space that gives us an advantage to use the Split (delimiter) command.
spoiler:
Now that we have it it is easy as pie. Each Morse code now is a separate element in the array that has been crated.
The only thing we need to know is how to convert the Morse into digits and number. For that we use Google to fine the translation table and personally I liked this site http://ling.ucsc.edu/~hank/morseabc.html. Now that we have the codes and all what we need to do is loop and compare, loop and compare, loop and compare and so on and so on.
TIP: I usually prefer to put the code in the Form_Load in order to win some time over also at the end when I get the answer I use Clipboard.SetText(my answer) to copy the answer to the clipboard. So that only leaves me with opening up the program then quickly pressing Control+V and submitting the answer.
That would be all and if you have any questions or suggestions please leave comments below. Happy hacking everybody!
Cast your vote on this article 10 - Highest, 1 - Lowest
Comments: Published: 7 comments.
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.