The problem report at the front level is here http://blog.csdn.net/richytang/article/details/12257467 (第4-5 Guan)
6th off: http://www.pythonchallenge.com/pc/def/channel.html
The name is: Now there are the pairs. There is only one picture in the clearance, it is a zipper. Only the first line in the source code is useful information. A note, is a zip.
It really made me start without a clue. Later on the web, the comments were placed in the first line, allowing you to replace the HTML in the URL with a zip. So we got a channel.zip compression package ... (The feeling of IQ is instantaneous enough). OK, download the zip file, we first look at the contents of the file: a bunch of digital TXT file + a Readme file. Read gives two hints, one is starting from 90052, the other is: The answer is in the zip. Then the first hint of the document looked, and found something similar to the one before it: Next is xxxx. The second hint is whether the use of the ZipFile module means. (This obviously does not refer to the Python zip function). Don't worry, just do it like that, let's take a look at the Zip module first.
The Zip module is mainly used to compress, decompress and process the ZIP format. Simply put, the zip file is handled as a file, and it's not zip. But it's clear that this information is not going to help us further, but let's do it the same way:
nothing = ' 90052 '
while True:
try:
fp = open (' channel/' +nothing+ ' txt ', ' r ')
Text = Fp.read ()
nothing = Text.split () [-1]
print (Nothing)
fp.close ()
except Filenotfounderror:
print (text, ' Need to try Manually ', Sep = ' \ n ') break
The final output is: Collect the comments. What is it.
A detailed look at the Python3 zipfile module. We found that the file we were dealing with was zipfile this class. What does this class have? Help:
>>> Import ZipFile
>>> Help (ZipFile. ZipFile) Help on
class ZipFile in module ZipFile:
class ZipFile (builtins.object)
| Class with methods to open, read, write, close, list zip files. z = zipfile (file, mode= "R", Compression=zip_stored, Allowzip64=false)
|
| File:either the path to the file, or a File-like object.
| If It is a path, the file would be opened and closed by ZipFile.
| Mode:the mode can be either read "R", write "W" or Append "a".
.../omit
Data descriptors defined here:
|
| __dict__
| Dictionary for instance variables (if defined)
|
| __weakref__
| List of weak references to the object (if defined)
|
| Comment
| The comment text associated with the ZIP file.
Look, finally see the things you want to find (this process is all tears AH). So how do you get this comment?
>>> Help (ZipFile. Zipfile.getinfo) Help on
function GetInfo into module ZipFile:
getinfo (self, name) return the
instance of Zipin Fo given ' name '.
Name is the file name. Then it's OK to call each file once. Of course, you have to tune in the Order of nothing. Here's the code:
Import ZipFile as ZF
ZFP = ZF. ZipFile (' Channel.zip ') nothing
= ' 90052 '
li = []
while True:
try:
fp = Zfp.open (nothing+ '. txt ', ' R ')
Text = Fp.read (). Decode () Nothing
= Text.split () [-1]
li.append (zfp.getinfo (nothing+ '. txt '). Comment.decode ())
fp.close ()
except Keyerror:
print (' It "s time to check manually ', Sep = ' \ n ')
Break
print ('. Join (LI))
The above code is worth saying except for some functions of the zipfile itself (these help are available), which is the decode () function. This function is the conversion of the binary (that is, the bytes type of Python) to the STR type. The default parameter is ' Utf-8 ', which is not given. This is very different from the py2k, encoding and decoding is also a high-level topic of python3.
Run the results at a glance, hockey. Replace the URL into: http://www.pythonchallenge.com/pc/def/hockey.html. Jump forward is to let you look at the letters. Again, in the output, each letter is composed of small letters, is oxygen. Space problem, here is not given the result chart. So the next pass, enter.
7th off: http://www.pythonchallenge.com/pc/def/oxygen.html
That's a close. Topic: a smart guy. The level has only one picture, the source code does not have any prompts. A little article on the picture, a gray bar:
It seems that only the picture can be processed. Look at the picture with Gimp first. Get some very useful information:
The whole picture is a 629x95 pixel; the gray belt is the y direction 43-53,x direction 0-609.
Then look up the library of Python third party processing pictures (especially for py3k). There are more PIL on the Internet. Go to the official website, see PIL Update to support python2.x will not update. Later still found the cow people compiled support python3.3.2 version of the PiL exe file, link https://pypi.python.org/pypi?name=Pillow&version=2.2.1&: Action=files. The old rules, after importing the package, help, find the open function is useful. Also, the value of the Y-direction of the line is the same (the same color). So we'll try a random sample of 43-53 in the Y direction with the GetPixel () method:
From PIL import Image
img = image.open (' oxygen.png ')
data = [Img.getpixel ((i,43)) for I in Range (0,609)]
prin T (data)
Output results We see some clues: each pixel is a four-tuple, the first three values are the same, and the last one is 255. Later it was known that this is the RGBA mode, regardless of. There is another point that I found a long time, every seven is a cycle, assuming that the single out of the R value, every seven will have a difference (should be the number of this off: the 7th). Then it is processed in 7, and the first value in the four-tuple group is taken. Got a bunch of different numbers. At this point, another hint that the ASCII code is 255, that is exactly the value of these rgba is not the perfect match. Then treat the values as ASCII and combine them into strings:
From PIL import Image
img = image.open (' oxygen.png ')
data = [Chr (Img.getpixel ((i,50)) [0]) to I in range (0,609,7) ]
print ('. Join (data))
The output is:
Smart guy, made it. The next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
So we're close to the answer. In the end, convert these ASCII:
Source = [The 116, the 114, the 116, the 121]
print ([Chr (i) for I-source])
The answer is integrity. Well, the terrible one is finally over. 7th is so difficult, then dare not imagine ah ...
Next Link: http://www.pythonchallenge.com/pc/def/integrity.html