It's Time To Learn PYTHON! (record of python challenges)
It’s Time To Learn PYTHON! (record of python challenges)
Sometimes refer to the solutions to all the passes: HackingNote Python Challenges Solutions
The First Pass
The gibberish displayed on the screen is a passcode which is coded with Caeser cipeher, one of the simplest encryption techniques. From the Wikipedia, we can know that
It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on.
So I first wrote a code like this:
1 | para = input () |
Apparently, it is quite cumbersome. After decoding, we can learn from the text that $string.maketrans ()$ is recommanded to be used when facing such problem. So I rewrote the code:
1 | intext = "abcdefghijklmnopqrstuvwxyz" |
And the code is simpler now. Follow the tips translated, you only need to apply the encryption technique into the url “map” so that we can get “ocr”. After replacing “map” with “ocr”, we can get to the second pass.
The Second Pass
recognize the characters. maybe they are in the book, but MAYBE they are in the page source.
It hints us the solution hides in the page source. After opening the page source, we can see another hint and a long string containing various notations, that is
It hints us to find the characters. But how can we get the content of page source? There is a package named $\text{urllib}$, where we can import function urllib.request.urlopen to load raw html data. Then we use function read and decodeto decode the html and use regular expression to extract the comment blocks.
Now we have transformed the comment blocks into a string without \n, so the solution is obvious now. We apply re.findall to the string again then we can find the answer $\text{equality}$
The code is shown below
1 | from urllib.request import urlopen |
The Third Pass
Nearly the same as the second pass.
1 | from urllib.request import urlopen |
The Forth Pass
From this pass I learn that we can use notation as %s to temporarily substitude a variable, and when you want to call the variable, you only need to add a % notation between two variables.
1 | from urllib.request import urlopen |
The Fifth Pass
According to the page source, we replace the peak.html with banner.p and enter a page full of notations. But we find it difficult to recongnize the characters after decoding the notations in utf-8. In the meantime, we can see a hint in the original page, that is, $\text{pronounce it}$. The pronunciation of $\text{peak}$ is like a object serialization module in Python —— $\text{pickle}$. It hints that we need to decode in the form of pickle, namely,
1 | myURL = urlopen ("http://www.pythonchallenge.com/pc/def/banner.p") |
Then it is easy to get to a banner like this:
The problem is resolved right now. The full code is shown below:
1 | from urllib.request import urlopen |
The Sixth Pass
Nearly the same as the previous passes, though the information in page sources is shifted to the zip. We only need to replace the module of urllib with zipfile
1 | import zipfile, re |
The answer is oxygen
The Seventh Pass
In this pass, we only have an image and do not know what to do. But there is a grey bar in the middle of the image, which may be the key. We use urlopen to load the image as binary, and use BytesIO to decode, then use the open function in Image module to obtain the data of the image.
1 | img = Image.open (BytesIO (urlopen ("http://www.pythonchallenge.com/pc/def/oxygen.png").read())) |
After using the getpixel to get the data of certain pixel, we get a list of (R, G, B, alpha). Then merge the seven same tuples, and get the representation in $ASCII$ of the integer of (R, G, B).
1 | lst = [img.getpixel ((x, img.height / 2)) for x in range (img.width)][::7] |
Print the result, we now have another hint:
smart guy, you made it. the next level is $[105, 110, 116, 101, 103, 114, 105, 116, 121]$pe_
Following the hint, we do the same process again such that we can get the answer.
$integrity$
1 | from urllib.request import urlopen |
The Eighth Pass
Decode the username and password in the page source in the form of bzip2
1 | import bz2 |
Or you even can find the answer in the page source…
The Ninth Pass
The number datas in the page source are the coordinates of some dots, we need to use the ImageDraw module in PIL to draw.
1 | first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,329,170,320,170, |
The Tenth Pass
The sequence you get by clicking the bull is called $\text{look-and-say sequence}$. From $Google$, we can see that
To generate a member of the sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit.
It is easy to use regular expression in $\text{Python}$ to obtain the target string.
However, I cannot understand I am supposed to regard my regular expression string as raw string, instead of using it to find the characters straightly.
1 | import re |
