"Political freedom is a society's safety valve, allowing the passionately critical a nonviolent way to express their dissatisfaction with the status quo." --David Cole
Hello. Welcome to my tutorial/article for Programmin Challenge 2.
This is my first article so I'm pretty sure it's far from flawless, but you'll have to deal with that. ;)
I hope this article will give you enough help to complete the challenge.
When you open the challenge you are provided with an image.
The white dots on said image all have certain distances between them, which provide you with ASCII codes.
These ASCII codes then give you a Morse coded text that you need to decipher.
(If you don't know anything about Morse code, I suggest you look it op Wikipedia).
The easiest way to handle this challenge, is to make a loop which checks every pixel for it's color and then do the following:
- If it's black, add one to a variable
- If it's white, add the character corresponding with the ASCII code you have stored in the variable to the string of characters and set the variable back to 0
(By adding 1 each time the pixel is black, you measure the distance between two whites)
Then finally replace all the Morse codes in the string by their textual equivalents.
Programming Language:
I suggest you use an easy programming language for this challenge because you don't need any hard operations.
I used PHP because it almost always comes with the GD-Image Manipulation library which makes it easy to check pixelcolors.
Of course it will be too spoily if I just supply with all the necessary code, so I will only give you minimum pseudo-code to help you better understand how to complete the challenge.
First we need to determine the distances between the white dots.
We need a construction that will test each pixel for a white color.
CODE :
for row=0; row<imageheight; row++
for column=0; column<imagewidth; column++
if pixelcolor(row, column) == white
then
// actions
end
end
end
To keep track of when the last white pixel was and to determine the distance between them, it's probably best to add 1 to a certain integer each time you find a black pixel, and to reset that integer each time you find a white one.
CODE :
for row=0; row<imageheight; row++
for column=0; column<imagewidth; column++
if pixelcolor(row, column) == white
then
ascii[] = i
i = 0
else
i++
end
end
end
You now have an array containing the ASCII values of the morse code characters.
This is a very small step, because most languages already have a function for translating ASCII codes to their textual equivalents.
If you happen to use a language that doesn't support this, you only need a loop that checks every entry in the ASCII array and replaces it with the character.
This won't be too hard because you only have to replace four ASCII codes, namely those for '.', '-', ' ' and '/'.
For "unknown" reasons, no language supports the translation from morse code to text, so we have to do this ourselves.
This is done the same way as you would have done Step 2 by hand, only with many more replacements to be made.
For what I know, the best way to do this, is also the most annoying way.
You have to use a string replacement function (it's not a language if yours doesn't have it :P) exactly 36 times (26 letters and 10 numbers).
I hope this article has supplied you with enough help to complete the mission but hasn't given you the direct solution.
This article is my work and my work only (except for the wikipedia image), and you are not allowed to copy anything of it.
No animals were hurt during the development of this article.
Unless family members are animals too.
Cast your vote on this article 10 - Highest, 1 - Lowest
Comments: Published: 13 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.