<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Conflagration of Randomness &#187; hacking</title>
	<atom:link href="http://blog.robertkania.com/tag/hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.robertkania.com</link>
	<description>A blog about technology, college, and life.</description>
	<lastBuildDate>Fri, 23 Apr 2010 04:16:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hack this Site Programming Problem 2 Solution</title>
		<link>http://blog.robertkania.com/2010/02/09/hack-this-site-programming-problem-2-solution/</link>
		<comments>http://blog.robertkania.com/2010/02/09/hack-this-site-programming-problem-2-solution/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 21:00:16 +0000</pubDate>
		<dc:creator>Robert Kania</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.robertkania.com/?p=602</guid>
		<description><![CDATA[A few years ago I joined the site, Hack This Site in order to practice coding and see how much I knew.  Although the name is suggestive of illegal material, this site is in no way promoting hacking.  It simply is a site to practice programming and learning better techniques.  One of the challenges, Programming [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="lytebox" href="http://blog.robertkania.com/wp-content/uploads/2010/01/hts-program2.gif"><img class="alignright size-medium wp-image-603" title="hts-program2" src="http://blog.robertkania.com/wp-content/uploads/2010/01/hts-program2-300x243.gif" alt="" width="300" height="243" /></a>A few years ago I joined the site, <a href="http://www.hackthissite.org">Hack This Site</a> in order to practice coding and see how much I knew.  Although the name is suggestive of illegal material, this site is in no way promoting hacking.  It simply is a site to practice programming and learning better techniques.  One of the challenges, Programming Problem 2 involves writing a program to take an image filled with black and white pixels, find the distance between the white pixels, which are ascii characters.  Convert these ascii characters then into Morse code, which then is translated into numbers and letters.  I spent some time initially looking for a language that could read an image in pixel by pixel and the one I settled on was Python.  This was the second program I had written in Python.</p>
<p>The exact instructions for the program were</p>
<blockquote><p>The pixels in the above image are numbered 0..99 for the first row,  100..199 for the second row etc.                  White pixels represent ascii codes.                  The ascii code for a particular white pixel is equal to  the offset from the last white pixel.                  For example, the first white pixel at location 65 would  represent ascii code 65 (&#8216;A&#8217;),                   the next at location 131 would represent ascii code  (131 &#8211; 65) = 66 (&#8216;B&#8217;) and so on.</p>
<p>The text contained in the image is the answer encoded  in Morse, where &#8220;a test&#8221; would be encoded as &#8220;.- / &#8211; . &#8230; -&#8221;</p>
<p>You have 15 seconds time to send the solution.</p></blockquote>
<p>Now of course it says you have 15 seconds which is true and I did do it in 15 seconds, but since this site uses Javascript to count, you can simply disabe javascript to have unlimited time by using the Firefox plugin <a href="https://addons.mozilla.org/en-US/firefox/addon/722">NoScript</a>.</p>
<p>For example, the image I used was:</p>
<p><a href="http://blog.robertkania.com/wp-content/uploads/2010/01/PNG.png"><img class="size-full wp-image-605 alignnone" title="PNG" src="http://blog.robertkania.com/wp-content/uploads/2010/01/PNG.png" alt="" width="100" height="30" /></a></p>
<p>which gave the following numbers:</p>
<blockquote><p>45 46 46 32 45 46 46 32 45 46 46 46 46 32 45 45 45 32 46 45 32 45 46 45 32 46 46 46 32 46 46 46 46 32 46 45 45 45 45 32 46 45 32</p></blockquote>
<p>which was translated in the following ascii characters</p>
<blockquote><p>-..  -..  -&#8230;.  &#8212;  .-  -.-  &#8230;  &#8230;.  .&#8212;-  .-</p></blockquote>
<p>which produced the following output using Morse code to translate:</p>
<blockquote><p>dd6oaksh1a</p></blockquote>
<p>The code that I used to program this was:</p>
<pre>import Image
def multipleReplace(text, morse_code):
    for key in morse_code:
        text = text.replace(key, morse_code[key])
    return text
morse_code = {' .- ':'a',' -... ':'b',' -.-. ':'c',' -.. ':'d',' . ':'e',
            ' ..-. ':'f',' --. ':'g',' .... ':'h',' .. ':'i',' .--- ':'j',
            ' -.- ':'k',' .-.. ':'l',' -- ':'m',' -. ':'n',' --- ':'o',
            ' .--. ':'p',' --.- ':'q',' .-. ':'r',' ... ':'s',' _ ':'t',
            ' ..- ':'u',' ...- ':'v',' .-- ':'w',' -..- ':'x',' -.-- ':'y',
            ' --.. ':'z',' ----- ':'0',' .---- ':'1',' ..--- ':'2',
            ' ...-- ':'3',' ....- ':'4',' ..... ':'5',' -.... ':'6',
            ' --... ':'7',' ---.. ':'8',' ----. ':'9'}
im = Image.open("C:\PNG.png")
size = im.size
width = size[0]
height = size[1]
L = list()
last = 0
#The loop transforms the image into a list
#If the pixel is white, return 0, otherwise return 1
for i in range (0,height):
    K = list()
    for j in range (0,width):
        checker = (int)(im.getpixel((j,i)))
        if(checker == 1):
            K.append(1)
        else:
            K.append(0)
    L.append(K)
ascii = list()
count = 0
for i in range (0,height):
    for j in range (0,width):
        if(L[i][j] == 1): #determines if the pixel is on
            char = chr(count-last) #converts the distance
            #between the pixels to ascii
            if(char == " "):
                char = "  "
            ascii.append(char)
            last = count
        count+=1
morseCode = " "
for i in range (0,len(ascii)-1):
    morseCode += ascii[i]
morseCode += " "
print multipleReplace(morseCode, morse_code) #replaces the morse code
#with letters and numbers
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.robertkania.com/2010/02/09/hack-this-site-programming-problem-2-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
