ITeye博客

python challenge 6

he_lux · 2009-12-29 16:05 · python · 编程语言 · Markdown

第6题,网页上同样没有任何提示,查源码,作者在倡议捐款: The following has nothing to do with the riddle itself. I just thought it would be the right point to offer you to donate to the Python Challenge project. Any amount will be greatly appreciated.

除了这点内容,源码中还有一段:<-- zip --> 比较奇怪,这下又难住了,只有再次上网找线索了………… 原来是将网页URL后缀名改成zip,改完后会下载一个ZIP文件,打开后有一堆的txt文件,线索就在其中的一个readme.txt里: hint1: start from 90052 hint2: answer is inside the zip

打开90052.txt,内容是Next nothing is 94191,看来这题是跟第四题一样,找next nothing。同时要用到对ZIP的处理。 准备编程,将下载下来的channel.zip保存到本地环境。


import zipfile
import re

if __name__ == '__main__':
    
    z = zipfile.ZipFile('channel.zip', mode='r')
    
    prefix = '90052'
    surfix = '.txt'
    
    findNothing = re.compile('Next nothing is (\d*)').search
    
    while True:
        
        text = z.read(prefix + surfix);
        print(text)
    
        match = findNothing(text)
        
        if match:
            prefix = match.group(1)
        else:
            break

最后输出一句:Collect the comments. 去哪儿收集comments呢,再次看页面源码,也没什么特殊的comments,会不会是在zip文件里呢? 于是修改代码,使用ZipInfo类获取comment:


import zipfile
import re

if __name__ == '__main__':
    
    z = zipfile.ZipFile('channel.zip', mode='r')
    
    prefix = '90052'
    surfix = '.txt'
    
    findNothing = re.compile('Next nothing is (\d*)').search
    
    comments = []
    
    while True:
        
        text = z.read(prefix + surfix);
        print(text)
        
        match = findNothing(text)
        
        if match:
            prefix = match.group(1)
            comments.append(z.getinfo(prefix + surfix).comment)
        else:
            break
        
    print(''.join(comments))

最后打印出:




** 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 **




出来这个结果很惊讶,原来comment中包含有换行符,开始还以为会出一行长串字符呢。 HOCKEY应该就是过关答案了。

将hockey应用到url上,出现it's in the air. look at the letters. 原来还有个小关卡。这下晕了,开始以为是文字游戏,答案在“air”中,于是试了a,i,r三个字母的每种排列,无效,实在没办法了,上网找线索………… 原来,答案是oxygen,你能猜到吗?

(oxygen就是组成HOCKEY的小字母)

把oxygen应用到url上,过关。

通过这一题,学习到了zipfile的简单使用。

评论(1)

  1. #1 楼 · plmxsyuts6 · 2012-03-03 20:25

    it's in the air. look at the letters.

    答案oxygen氧气,不是

    (oxygen就是组成HOCKEY的小字母)

评论功能维护中,当前仅展示历史评论。