Programming 2

Put your programming skills to the test in these challenges.

Programming 2

Post by kirgy9 on Wed Aug 26, 2009 9:48 pm
([msg=28498]see Programming 2[/msg])

Ive successfuly made a program that reads the image, determines the difference between white pixels and outputs the morse code, its written in vb 2008 (Im new to C, so im going back to my roots). The problem im geting is im geting the string like this:

.-,.-,. -.-.-.- ---. ,--. ----., .,.--,

The problem which REALLY confused me is why are there 4 different types of charactors?? Any ideas?

I gathered the reason commas were present were because of an offset, I would move the offset but then there is a problem with spaces...making them a ! charactor.

Can anyone give me some pointers on what im doing fundementaly wrong?
kirgy9
New User
New User
 
Posts: 2
Joined: Tue Jun 24, 2008 5:56 pm
Blog: View Blog (0)


Re: Programming 2

Post by aNewHobby4me on Thu Aug 27, 2009 6:11 am
([msg=28513]see Re: Programming 2[/msg])

kirgy9 wrote:
.-,.-,. -.-.-.- ---. ,--. ----., .,.--,

The problem which REALLY confused me is why are there 4 different types of charactors?? Any ideas?

Can anyone give me some pointers on what im doing fundementaly wrong?


The devil is is in the details, or so they say. You seem to have an 'off by one' error. (44, ',') (45, '-') (46, '.') I had the same problem--my dots came out dashes, and my dashes came out commas.
"To understand recursion you must first understand recursion."
aNewHobby4me
Poster
Poster
 
Posts: 185
Joined: Thu Jan 08, 2009 5:44 pm
Blog: View Blog (0)


Re: Programming 2

Post by Bitbored on Thu Sep 03, 2009 3:40 pm
([msg=29037]see Re: Programming 2[/msg])

I made a VB.net application that loads in the image after I drop it into a folder on my desktop, reads it out using GetPixel, translates the Morse and tells me the result, it is a simple string with random letters AND numbers, apparently it's wrong, since after I click submit, it sais Sorry: Your answer is wrong...

I guess it isn't a bug in my application, since then it wouldn't create a nice string, but give loads of errors.

Can I post my code here?
Should the letters be Capitals are lower?
How many characters should the code count?
Bitbored
New User
New User
 
Posts: 2
Joined: Thu Sep 03, 2009 3:26 pm
Blog: View Blog (0)


Re: Programming 2

Post by FR34K on Fri Oct 01, 2010 2:20 pm
([msg=46888]see Re: Programming 2[/msg])

Im so proud this is the first one I did without stealing any code off google (i took the guts of the irc bot from an already existing bot that greets people when the join)

I am using these HTS challenges to teach myself C# and this one taught me so much

Tips for others:
Take it one piece at a time, you need:
1 part to "look" at the image
1 part to convert the image to code
1 part to decypher the code
and a final part to echo the code back

Hope that isnt to much :) (its another way of stating the instructions in easier terms i hope)
FR34K
New User
New User
 
Posts: 1
Joined: Wed Sep 29, 2010 2:10 pm
Blog: View Blog (0)


Re: Programming 2

Post by prizzy on Sun Feb 19, 2012 8:39 pm
([msg=64479]see Re: Programming 2[/msg])

FR34K wrote:Im so proud this is the first one I did without stealing any code off google (i took the guts of the irc bot from an already existing bot that greets people when the join)

I am using these HTS challenges to teach myself C# and this one taught me so much

Tips for others:
Take it one piece at a time, you need:
1 part to "look" at the image
1 part to convert the image to code
1 part to decypher the code
and a final part to echo the code back

Hope that isnt to much :) (its another way of stating the instructions in easier terms i hope)


I am doing the same exact thing. How did you breakdown the picture? Some conversion to an array, or GetPixel?

I haven't found a good way at all. I can use GetPixel, but it's pretty drawn out. And using this:

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
Bitmap bitmap = new Bitmap("PNG_white.png");
byte[] myArray = imageToByteArray(bitmap);

Returns an array with 3600 entries and it doesn't make sense.
prizzy
New User
New User
 
Posts: 5
Joined: Tue Feb 09, 2010 10:19 pm
Blog: View Blog (0)


Re: Programming 2

Post by QtDevl on Thu Feb 23, 2012 5:51 am
([msg=64570]see Re: Programming 2[/msg])

Bitmap myBitmap = new Bitmap("image.png");
...
Color pixelColor = myBitmap.GetPixel(x, y);

From here it's easy to loop through all x and y isn't it :P

PS: don't worry about numbers it gives you,do a basic test and print every pixel and see values..you should see only two of them...one is black the other one should be the white one :P
otherwise you can do : if(pixelColor == Color.White) do stuff
If freedom is outlawed, only outlaws will have freedom...
QtDevl
New User
New User
 
Posts: 22
Joined: Sat May 17, 2008 3:50 pm
Location: my own world
Blog: View Blog (0)


Re: Programming 2

Post by tostbrot21 on Sat Aug 04, 2012 12:21 pm
([msg=68509]see Re: Programming 2[/msg])

Hey Guys, had the same problem, you have to decrypt the morse string too, e.g. http://alldownunder.com/australian-convert/morse-code-conversion.htm
tostbrot21
New User
New User
 
Posts: 1
Joined: Sat Aug 04, 2012 12:19 pm
Blog: View Blog (0)


Re: Programming 2

Post by synstealth on Thu Aug 16, 2012 9:55 pm
([msg=68792]see Re: Programming 2[/msg])

Hey I seem to have some trouble decoding the png file since it is dynamically created from /prog/2/PNG/index.php file so I wrote a php script using cURL with GD, it appears to grab the image successfully but my code cannot read it properly, am I doing something wrong, here's my snippet and hope anyone can help and catch what I am doing here.


the first part is to grab the image, the second part is to decode
Code: Select all
<?

$source = 'http://www.hackthissite.org/missions/prog/2/PNG/';

curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$output = curl_exec($ch);
$fp = fopen('dots.png', "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
fclose($fp);

$imgFile =  'dots.png';
$im = imagecreatefrompng($imgFile);
imagepng($im,$imgFile);

$imgWidth = imagesx($im);
$imgHeight = imagesy($im);


$res='';
for ($y=0; $y < $imgHeight; $y++){
   for ($x=0; $x < $imgWidth; $x++){
   
      $ndx = imagecolorat($im,$x,$y);
      $aryColors = imagecolorsforindex($im,$ndx);
      
      print substr("R".dechex($aryColors['red']),-2);
      print substr("G".dechex($aryColors['green']),-2);
      print substr("B".dechex($aryColors['blue']),-2);
   
         
   }
}

synstealth
New User
New User
 
Posts: 2
Joined: Thu Aug 16, 2012 9:49 pm
Blog: View Blog (0)


Re: Programming 2

Post by wan26 on Fri Aug 17, 2012 12:16 pm
([msg=68799]see Re: Programming 2[/msg])

To break down the picture i chose the cimg library and converted it to txt, so i could see in the file what was being changed each time;

Code: Select all
void convertimg(){
CImg<unsigned short> img("PNG.png");
    img.save_ascii("hi5.txt"); // HTS PROG MISSION 2

}
User avatar
wan26
Experienced User
Experienced User
 
Posts: 91
Joined: Sun Jan 22, 2012 6:46 pm
Blog: View Blog (0)


Re: Programming 2

Post by Wasp256 on Fri Sep 21, 2012 11:26 am
([msg=69511]see Re: Programming 2[/msg])

Hi, could anybody please check if I receive the right code for the image
http://www.hackthissite.org/missions/prog/2/PNG

I receive the code: D8WC3D5KKP
Wasp256
New User
New User
 
Posts: 1
Joined: Sat Sep 15, 2012 10:23 am
Blog: View Blog (0)


Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests