Python Challenge level 12: “dealing evil”

Level 12 requires some hex-observation.

Hint 1: image evil1.jpg with a shuffled deck and five piles

The name evil1 seems suspicious, so maybe we can find something else poking around.

Fact 1: there are more evil?.jpg and an evil2.gfx

Fact 2: when inspected in an hex editor the gfx file seems to have several images interleaved. You don’t have to be a genius to recognize a JPEG header, but the GIF87a is much more obvious. Not everybody is used to reading binary files, but simply by watching you can get the idea that each file is shuffled every 5 bytes. So the task will be deshuffling evil2.gfx into 5 piles

Fact 3: when trying to retrieve file evil4.jpg a text appears “http://www.pythonchallenge.com/pc/return/evil4.jpg” and the source code is “Bert is evil! go back!”. This is not useful right now, but keep it in mind. It may come in handy in the future.

That’s a lot of text for one post ;) At least the task is clear. Two lines of code should suffice:

#!/usr/bin/env python
info=open("evil2.gfx").read()
[open("12_f%d.dat" %i, "w").write(info[i::5]) for i in range(5)]

My image viewer doesn’t really care for the file extension, so “.bin” suits me fine. Anyway you could allways use the file command in case yours cares.

Once we view the images, we get the link for Level 13.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

9 Comments »

 
  • Wahoo says:

    Thank you for sharing!

  • You’re welcome! And go on… the game gets even better! :)

  • FringeFX says:

    Great blog, thanks a lot for the awesome posts!

  • Bheema V says:

    I am using 2.6.1 and when I open the input or output file using your code, I essentially get garbage, unless I open the files in binary mode.

    Have you left this out as a) a test to the people copy pasting your code b) as something that is not needed in the version you are using (I have no idea about Python 3.0, and is it not necessary to open the files in binary mode in Python 3.0?)

  • Nope, I wasn’t testing anybody ;)
    It works just fine for me on Linux and 2.x. I suppose it is required to specify the binary mode on Windows since it makes distinctions, but I have no idea if other platforms require it too.

    Thanks for the note. Hopefully it will help others.

  • BgEddy says:

    Nice bit of code – I especially like the list comprehension to open and write to the five files while the list itself is superfluous. Very nice – I have never seen that pattern before but will use it again myself. Thanks.

  • Somebody says:

    Oh my God… “peak hell” was bad enough, but this level is really stupid.
    URL bruteforce, image file headers recognition… what’s next? native code?

    I’m amazed by you skills, but this is getting more and more weird.

  • drm / Gerard says:

    Wow. Some challenges I think, “hm, I’m pretty smart”. Challenges like these make me feel dumb in ways I have never loathed myself, LOL :D. I seem to get stuck on my own train of thought a bit too often.

    Thanks for the solution though! It taught me, next to humbleness, yet another feature of Python I did not know, extended slices :)

  • Welcome to GFXshare.us – Free GFX source for you…

    [...]Python Challenge level 12: “dealing evil” | UnixWars[...]…

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>