python challenge 6

第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里:
[color=red]hint1:[/color] start from 90052
[color=red]hint2:[/color] 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的简单使用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值