The Python Challenge Lv.6
作者 Ross Wan on 2011/08/25
Lv.6
打开第6关的网页,显示的是一张裤拉链的图片,”拉链”???第一时间,猜想到的是 Python 的 zip 内建方法、zipfile 内建模块,还有就是 zip 格式的文件。
查看网页的源文件,没什么可疑,尝试将网址最后的“html”改为“zip”,下载到“channel.zip”这个压缩文件 :) 用 7-zip 解压缩,发现里面有910个文本文件,一个 readme.txt 文件:
welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip
其它文件的内容大致如下:
Next nothing is xxxxx
这有点像第4关。先验证下那些文件的内容是否一致,是否有一个特殊的(或者答案就直接在那文件里呢):
import re, os
if __name__ == '__main__':
for filename in os.listdir('channel'):
filepath = os.path.join('channel', filename)
if os.path.isfile(filepath) and re.match(r'^\d+\.txt', filename):
f = open(filepath)
content = f.read()
f.close()
if not re.match(r'^Next nothing is \d+', content):
print('File: %s\nContent: %s' % (filename, content))
显示如下内容:
File: 46145.txt
Content: Collect the comments.
发现 “46145.txt”文件的内容是不一样的。“注释”?再用 z-zip 打开 channel.zip 这个压缩文件,查看其注释栏,的确压缩包里的部分文件是带注释的。再结合 readme.txt 文件的提示,将注释按顺序打印出来:
#!bin/python3
# coding=utf8
import re, zipfile
if __name__ == '__main__':
target = '90052'
z = zipfile.ZipFile('channel.zip')
while 1:
target_file = '%s.txt' % target
print(z.getinfo(target_file).comment.decode('ascii'), end='')
f = z.open(target_file)
match_obj = re.match(r'^Next nothing is (\d+)',f.read().decode('ascii'))
f.close()
if match_obj:
target = match_obj.groups()[0]
else:
break
z.close()
显示如下图案:
**************************************************************** **************************************************************** ** ** ** OO OO XX YYYY GG GG EEEEEE NN NN ** ** OO OO XXXXXX YYYYYY GG GG EEEEEE NN NN ** ** OO OO XXX XXX YYY YY GG GG EE NN NN ** ** OOOOOOOO XX XX YY GGG EEEEE NNNN ** ** OOOOOOOO XX XX YY GGG EEEEE NN ** ** OO OO XXX XXX YYY YY GG GG EE NN ** ** OO OO XXXXXX YYYYYY GG GG EEEEEE NN ** ** OO OO XX YYYY GG GG EEEEEE NN ** ** ** **************************************************************** **************************************************************
显而易见,下一关的网址正是:http://www.pythonchallenge.com/pc/def/hockey.html
且慢,别高兴太早~~~打开上面的网址,显示:
it’s in the air. look at the letters.
“这仍然是个谜,注意那些字母”,原来谜还未解完呢,留意“HOCKEY”各由什么字母组成——oxygey。答案终于出来了: http://www.pythonchallenge.com/pc/def/oxygen.html
Have fun :)