Page 1 of 2

lotsa dots

Posted: Mon Jan 19, 2009 8:08 pm
by megabreit
FYI: My "UNIX only" solution. All you need is wget and ImageMagick.
Just want to ask how you solved this challenge. I think my way of "converting" the image is a bit unusual,
but I could not imagine a faster and shorter way (even with perl):

Code: Select all

#!/bin/bash

wget --save-cookies=cookies --keep-session-cookies "http://www.hacker.org/challenge/chal.php?id=79&name=NAME&password=PASSWORD"
wget --load-cookies=cookies http://www.hacker.org/challenge/misc/stars.php
mv stars.php stars.png
# convert picture into xpm (kind of ascii art)
convert stars.png stars.xpm

result=""
index=0
export IFS="
"
cat stars.xpm|fgrep  .|grep -v \# |while read line
do
	((index+=1))
	if [[ $index -eq 8 ]]
	then
		var=$(echo $line|cut -c9,25,41,57,73,89,105,121|sed -e "s#\.#1#g" -e "s# #0#g")
		dez=$(echo "ibase=2; $var"|bc)
		printf "%c" $dez >>tmp_result
		index=-8
	fi
done
result=$(cat tmp_result)

echo $result
wget --load-cookies=cookies "http://www.hacker.org/challenge/chal.php?id=79&answer=$result&go=Submit&name=NAME&password=PASSWORD"

Posted: Fri Mar 27, 2009 4:39 pm
by Excalibur1974
my solution was a small java application, wich loads the picture and then:

Code: Select all

--snipp---
  try
                {
                        url = new URL( "http://www.hacker.org/challenge/misc/stars.php" );
                        con = url.openConnection();
                        con.setRequestProperty("Cookie", cookie);

                        BufferedImage img = ImageIO.read(con.getInputStream());

                        for (i=0;i<12;i++) // foreach row
                        {
                                b=0;

                                for ( j=0;j<8;j++) //for each bit
                                {
                                        x=8+(j*16);
                                        y=8+(i*16);

                                        pixel=img.getRGB(x,y);


                                        if ( pixel == -1644826)
                                        {

                                                b=b+(int)Math.pow(2,(7-j));

                                        }
                                }
                                answer=answer+(char)b;
                        }



                }
                catch (Exception e)
                {
                        System.out.println("error " + e);
                }

                System.out.println(filteredline);

                answerstring="http://www.hacker.org/challenge/chal.php?id=79&answer="+answer;
--snapp--
But i guess this is not the shortes way...
:D

Posted: Sat Mar 28, 2009 8:24 pm
by PeterS
it can be done in very few lines of python, but it gets a bit dirty ;)

Code: Select all

#!/usr/bin/env python

import Image

img = Image.open("stars.png")
width, height = img.size
print "".join([chr(int("".join(["1" if 200 < min(img.getpixel((x,y))) else "0" for x in xrange(7, width, 16)]), 2)) for y in xrange(7, height, 16)])

Posted: Sun Mar 29, 2009 1:24 am
by megabreit
This is a good example of how to write dirty code in Python! :shock: I was told that this is impossible. Or did you just remove the indentation to confuse your audience? :lol:
I didn't know that Python supports reading (and probably writing) of image files...

Posted: Mon May 18, 2009 3:28 am
by nomen
In Firefox and SeaMonkey at least, this can be conveniently solved from inside the browser, which I thought was a fun way to do it.

Code: Select all

var
  cheight = 600, cwidth = 200,
  startx = -1, starty = -1,
  b = 1, cbyte = 0,
  s = '';

var canvas =
  document.createElementNS("http://www.w3.org/1999/xhtml", "html:canvas");
canvas.height = cheight;
canvas.width = cwidth;

var ctx = canvas.getContext("2d");
ctx.drawWindow(window.content, 0, 0, cwidth, cheight, "rgb(0,0,0)");
var mid = ctx.getImageData(0, 0, cwidth, cheight);

for (var y = 0; y < cheight; y++) {
  for (var x = 0; x < cwidth; x++) {
    b = (y * cwidth + x) * 4;
    if (mid.data[b] == 223 &&
        mid.data[b+1] == 145 &&
        mid.data[b+2] == 44) {
      startx = x+8;
      starty = y+8;
      break;
    } // found
  } // for columns
  if (startx > -1) break;
} // for rows

if (startx > -1) {
  for (var y = 0; y < 16; y++) {
    cbyte = 0;
    for (var x = 0; x < 8; x++) {
      b = mid.data[((starty+y*16)*cwidth+startx+x*16)*4];
      if (b == 230) {
        cbyte += (1 << (7-x));
      } else if (b < 100) {
        break;
      }
    } // for columns == bits
    if (b == 0 || cbyte == 0) break;
    s += String.fromCharCode(cbyte);
  } // for rows == bytes 
  window.content.document.getElementsByName('answer')[0].value = s;
} // if image was found

Posted: Sun Jun 21, 2009 11:59 pm
by coderT
I don't know how to convert the image into data which I need to use, so I just keep refreshing the page and wait for a short one, and type really fast, then copy and paste the answer...

Posted: Mon Jun 22, 2009 1:23 am
by therethinker
coderT: cheater :P

@megabreit re PeterS: that last line is "valid", it didn't just have indentation removed. It just uses the functional paradigm of python. Once you use functional programming (usually from another language) you start to use it all the time in python :D

Posted: Tue Sep 01, 2009 10:41 pm
by mmhckb
Stupid vb code:

Code: Select all

Public Class Form1


    Private Sub Image_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Image.Click
        Dim file_name As String = Application.ExecutablePath
        file_name = "C:\Users\Craig\Desktop\Challenges\hackerorg\stars\stars.php.png"

        Dim row As Integer
        Dim col As Integer
        Dim currentColor As Color
        Dim binString As String = ""
        Dim outputString As String = ""

        ' Load the picture into a Bitmap.
        Dim bm As New Bitmap(file_name)

        ' Display the results.
        picImage.Image = bm
        PicImage.SizeMode = PictureBoxSizeMode.AutoSize

        'start at 8, add 16 for each row down
        'same from left

        For row = 8 To bm.Height - 8 Step 16
            For col = 8 To bm.Width - 8 Step 16
                currentColor = bm.GetPixel(col, row)
                If currentColor.ToArgb = -2125524 Then
                    binString = binString & 0
                Else
                    binString = binString & 1
                End If
            Next
            outputString = outputString & Chr(BinToInt(binString))
            binString = ""
        Next

        Outbox.Text = outputString
    End Sub

    Function BinToInt(ByVal BinaryNumber As String)

        Dim Length As Integer
        Dim TempValue As Integer
        'Get the length of the binary string
        Length = Len(BinaryNumber)

        'Convert each binary digit to its corresponding integer value
        'and add the value to the previous sum
        'The string is parsed from the right (LSB - Least Significant Bit)
        'to the left (MSB - Most Significant Bit)
        For x = 1 To Length
            TempValue = TempValue + Val(Mid(BinaryNumber, Length - x + 1, 1)) * 2 ^ (x - 1)
        Next

        BinToInt = TempValue

    End Function

End Class

Posted: Tue Sep 01, 2009 11:04 pm
by nighthalk
i used autoit =P load page click go click textbox done

Code: Select all

sleep(2000)
Dim $x
Dim $y
$x=65
$y=385
$var=PixelGetColor ( $x , $y )
While $var<>1579032
$var2=0
$var=PixelGetColor ( $x , $y )
if $var=15132390 then
$var2=$var2+16
endif
$var=PixelGetColor ( $x+15  , $y)
if $var=15132390 then
$var2=$var2+8
endif
$var=PixelGetColor ( $x+30  , $y)
if $var=15132390 then
$var2=$var2+4
endif
$var=PixelGetColor ( $x+45  , $y)
if $var=15132390 then
$var2=$var2+2
endif
$var=PixelGetColor ( $x+60 , $y )
if $var=15132390 then
$var2=$var2+1
endif
if $var2==0 then
send("{Enter}")
else
$key=Chr(96+$var2)
send($key)
endif
$y=$y+16
wend

Posted: Thu Feb 25, 2010 1:23 pm
by zjorzzzey
Maybe a little dirty, but I just wrote a bit of javascript in firefox (using the firebug console)

Code: Select all



img = new Image();
img.src = 'misc/stars.php';

canvasEl = document.createElement('canvas');
canvasEl.width = '128';
canvasEl.height = img.height;

document.body.appendChild(canvasEl)
canvas = canvasEl.getContext('2d');

canvas.drawImage(img,0,0);

num_ch = Math.floor(img.height / 16);
ans = '';
for(h=0;h<num_ch;h++)
{
    n_ch = 0;
    for(w=0;w<8;w++)
    {
        imgData = canvas.getImageData((8+16*w),(8+16*h),1,1);
        
        bit = (imgData.data[2] == 230) ? 1 : 0;
        n_ch+= Math.pow(2,(7-w))*bit;
    }
    ch = String.fromCharCode(n_ch);
    ans+= ch;
}
document.forms[1].elements[0].value = ans;
document.forms[1].submit();


Posted: Thu Jan 27, 2011 4:16 am
by DaymItzJack
I did it just like everyone else, I'm just wondering though, would it be possible to stop the timer?

I managed to extend and even stop the timer using javascript (just pasted javascript code right into the url using javascript:) but even if i solved it after the 20 seconds, it said it was too late. I'm guessing the php has a timer in it too, or how else would it know if I extended the time?

Posted: Thu Jan 27, 2011 6:30 am
by CodeX
it wouldn't be a timer as such but a timestamp from the last time you requested the page or some part of the page (such as the image which appears to only change after requesting the challenge page), if the time you submitted your answer is greater than timestamp+20 then you get a rejection message, this method doesn't really offer itself up for exploitation unless your willing to wait until 03:14:07 19/01/2038 for the timestamp to overflow (guessing that there is no timestamp >=timestamp && timestamp <= timestamp + 20) :P

Posted: Wed Mar 09, 2011 12:38 pm
by mjb
I just solved it with a little PHP script:

Code: Select all

<?php
	$im = imagecreatefrompng('http://www.hacker.org/challenge/misc/stars.php');
	$sol = "";
	for($i = 0; $i < 10; $i++)
	{
		$string = "";
		for($j = 0; $j < 8; $j++)
		{
			$string =$string.((imagecolorat($im, $j*16 + 8 , $i*16 + 8) == 14651692)?"0":"1");
		}
		$sol .= chr(bindec($string));
	}
	echo $sol;
?>

Posted: Fri Jun 24, 2011 9:38 pm
by Grevas
If you want to watch you script working, i did it with some autoit (yeah, the start coordinates are predefined - too lazy to do a search)

Code: Select all

HotKeySet("{DEL}", "quit")

$sx = 1297
$sy = 520

$row = 0
$bullet = 0

$xstep = 16
$ystep = 16

$code = ""
$string = ""

While 1
	Sleep(10)
	
	if $bullet == 8 Then
		$row += 1
		$bullet = 0
		
		$string = $string & Chr($code)
		$code = 0
	EndIf
	
	Mousemove(1297 + ($bullet * $xstep), 520 + ($row * $ystep), 0)
	$color = PixelGetColor($sx + ($bullet * $xstep), $sy + ($row * $ystep))
	
	if $color == 0xE6E6E6 Then
		$bit = 1
	ElseIf $color == 0xDF912C Then
		$bit = 0
	Else 
		$bit = "x"
		Mousemove($sx + ($bullet * $xstep), $sy + ($row * $ystep), 0)
		ToolTip($string, $sx + (7 * $xstep) + 70, $sy + (($row-1) * $ystep))
		Sleep(20000)
		Exit
	EndIf
	
	$code += $bit * 2 ^ (7 - $bullet)
	ToolTip($string, $sx + (7 * $xstep) + 70)
	$bullet += 1
WEnd


Func quit()
	Exit
EndFunc

Posted: Fri Sep 23, 2011 7:13 pm
by zafarrancho
did it in one line:

# convert -resize 8 -black-threshold 70% -negate stars.php.png pbm:- | sed -n 3p