Python Challenge - Part 1
A couple of days ago my girlfriend told me about this quiz she found - the python challenge. Its basically a web quiz containing levels and you progress levels by solving puzzles. If you’ve ever heard of NotPron, you know what I’m talking about. The puzzles on the python challenge are designed in a way so that you have to utilize some algorithm or similar to solve them and I thought that might be a fun way to learn something new. I’ll detail how I solved each level and which problems I faced in doing so.If you plan on doing the challenge yourself, you might now want to continue reading.
Level 0
A picture of a number, and the hint to change the URL. Simple,right? Well, no. Actually its 2 to the power of 38. In python we can calculate that number using math.pow(2, 38)
.
Still easy enough, could have done that without python.
Level 1
A picture of some text with arrows. Also more garbled text. Probably means that we should shift the letters by a certain number, which remind me of the Caesar cipher. So we simply have to calculate the distance of the given letters (using ASCII codes) and apply that shift to the message.
The first result is still a bit garbled, which is because we didn’t consider that shifting the last
letters of the alphabet results in the ASCII-Codes of signs like ‘{’. So we add the case where newOrd > 122
.
Now we get the proper message, which tells us to apply the shift to the URL.
Level 2
Well, this is a bit misleading. The title of the page is ‘OCR’, but luckily the hint tells us to actually look in the page’s source. There we find a ton of text in the comments and the note to find all rare characters. So let’s add any new character to a dictionary as key and increment the value of that entry by 1 if we find that character again. Then we only have to find those entries with minimal occurrences. But watch out: If we try to do that using a ‘normal’ dictionary we get only nonsense. Better make sure that the entries remain in the order in which they are added using OrderdDict.
Level 3
The hint tells us that we should look for a small letter surrounded by exactly 3 bodyguards. Looking at the source code reveals a bunch of text - again. I was spoiled at this point, because I already knew that ‘Bodyguards’ meant upper-case letters. The resulting code is not exactly efficient, but it does the trick.
Level 4
Okay, this is new. There is no significant source code, and the text just says ‘linkedlist.php’. Huh, probably should change the file extension to ‘.php’. Comments on that page tell us to follow the chain and we see that there is a link to another page. And that page contains the instruction to go to another number. Probably should not try this per hand. After researching how to do requests using urllib2 we can parse the number from the page content, modify the URL for the next request and do that all over again.
Now, after the site refused to load a couple of times the code actually runs for some time - until it fails. Let’s figure out why. If we print out the page content we see that the last page actually contains an instruction to divide the last number by 2. After we adjust the function step
to handle that case we can continue.
Level 5
This one was mean. Again, I was spoiled because my girlfriend had asked me minutes before if there was such a thing as ‘pickle’ in Python. Well, I had no clue, but google tells us that, yes, there is such a thing. pickling appears to be some sort of object serialization. The source code of the page contains a lot of weird text, so our goal should be to unpickle that text. The code is pretty straight forward.
Unpickling gives us… a list with more stuff. Great. As there appear to be only hash-tags and empty spaces in that list we can conclude that we should probably arrange its contents into some sort of ASCII-Art. The sum of the digits in the list always equals 95, so that seems to be the width of the result. Printing each character the number of times specified gives us the solution.
Level 6
I remember this one, because at this point I knew to much for my own good. I was already familiar with the concept of zip so I asked myself: “What, I can zip not only lists but also text? What does that do?” Well, don’t you try, because it is utterly wrong. The solution is simple: Change the ‘.html’ in the URL to ‘.zip’.
The zip file we receive contains a lot of files with numbers as name and a read-me file. So, we do the same thing we just did but with text files. Not that exciting.
The final text file tells us to collect the comments. Which comments? Luckily we already found information how to extract file info from zip files and change our code accordingly.
We get one answer, change the URL accordingly and are subsequently stumped what the hell THAT is supposed to mean. Luckily the stumping doesn’t last long, and we conclude that we have to look at the letters the previous answer was made of. In retrospect, that was obvious.
Level 7
This level contains only an image with some grey scale pixels. Probably we should have a look at the RGB-Values of the grey squares. Hmm, the range of those values looks familiar. Could it be… ASCII? Again? Yeah, sure it is. So basically we convert the grey squares to characters and get the solution.
Level 8
The source code of the level reveals that there is link to clock on. Also some encoded user name and password. What for? Let’s click on the link and find out. So, it is pretty obvious that we should decode the given data. But which encoding. After some unsuccessful attempts using zlib we conclude that we did NOT try the right thing. Some more googling shows that we might want to try using bz2.
It seems that did the trick!
Level 9
That should be another easy one. Connect the dots? The stuff in the comments should be coordinates then. Let’s use PIL. The code is very straight forward.
I’ll write about the next few levels in the next part of this series.