hackthissite.org ascii code picture challenge

I recently tried the second programming mission on hackthissite.org and I found it very fun to code it.

When you start the challenge you get a picture like this thing:

hackthissite.org ascii picture

There is a hidden message in this picture. The description of this challenge was:

The ascii code for a particular white pixel in the picture is equal to the offset from the last white pixel. The text contained in the image is the answer encoded in Morse.

So I wrote a little PHP script that scanned the picture line for line and counted the offsets, put the offset info into ASCII Code (which got me morse code) and then finally translated morse code back to normal letters.

This is what my script decrypted from the image above:

[+]String: -- --.- .--. ..--- ----- --... .- ...-- .... .-
[+]Translated from morse: mqpaha

So the password of this stage was "mqpaha"

Here is my code of course:

<?php
/*******************************************************
* Hackthissite programming challenge #2
* by Christian Haschek (2012)
* Blog: http://futurelopment.blogspot.com/
* 
* Translates a special kind of picture to morse
* and morse to ascii
*
* feel free to steal
*******************************************************/
$image='Download.png';
$im = imagecreatefrompng($image);

for($y=0;$y<imagesy($im);$y++)
{
 for($x=0;$x<imagesx($im);$x++)
 {
  if(imagecolorat ($im,$x,$y))
  {
   $str .= chr(($count-$lastfound));
   $lastfound = $count;
  }
  $count++;
 }
}

echo "[+]String: $str\n";
$arr = explode(' ',$str);

foreach($arr as $i)
{
 $morse .= translateMorse($i);
}

echo "[+]Translated from morse: $morse\n";

function translateMorse($code)
{
 switch($code)
 {
  case '.-': return 'a';
  case '-...': return 'b';
  case '-.-.': return 'c';
  case '-..': return 'd';
  case '.': return 'e';
  case '..-.': return 'f';
  case '--.': return 'g';
  case '....': return 'h';
  case '..': return 'i';
  case '.---': return 'j';
  case '-.-': return 'k';
  case '.-..': return 'l';
  case '--': return 'm';
  case '-.': return 'n';
  case '---': return 'o';
  case '.--.': return 'p';
  case '--.-': return 'q';
  case '.-.': return 'r';
  case '...': return 's';
  case '-': return 't';
  case '..-': return 'u';
  case '...-': return 'v';
  case '.--': return 'w';
  case '-..-': return 'x';
  case '-.--': return 'y';
  case '--..': return 'z';
  default: return false;
 }
}
Tags: ascii challenge code function graphics hack hackthissite image imagecreate imagesx morse php png translator

Comment using SSH! Info
ssh f6114@ssh.blog.haschek.at

Comments


Get new posts by email
(~ one email every couple of months & no spam)