python挑战题 http://www.pythonchallenge.com/pc/def/map.html

来源:互联网 发布:知乎引流话术 编辑:程序博客网 时间:2024/05/16 05:43

http://www.pythonchallenge.com/

很好玩的一个网站

把url中的pc改为pcc,可以查看前一关的答案


第0关:http://www.pythonchallenge.com/pc/def/0.html

Hint: try to change the URL address

第一反应当然是将url中的0改为1,果然可以打开,页面提示【2**38 is much much larger.】,于是再将1改为2的38次方,pass


第1关:http://www.pythonchallenge.com/pc/def/map.html

字符串转换 a->c, b->d,....,y->a, z->b,就是字符的ascii码+2

可以用string.maketrans()函数,将map转换成ocr,替换到url中,pass

src2 = r"map"
map = string.maketrans('abcdefghijklmnopqrstuvwxyz', 'cdefghijklmnopqrstuvwxyzab')
print src2.translate(map)


第2关:http://www.pythonchallenge.com/pc/def/ocr.html

找出图片中的CHARACTER,我是从网页源码中的那一长串“乱码”中找出正常的字符[a-z][A-Z],得到结果equality, pass


第3关:http://www.pythonchallenge.com/pc/def/equality.html

One small letter, surrounded by EXACTLY three big bodyguards on each of its sides

网页标题就是re,很明显是要正则表达式了,弱项啊。两边都有3个大写字符保护的小写字母

得到结果:linkedlist

import urllib2  
import re
f = urllib2.urlopen('http://www.pythonchallenge.com/pc/def/equality.html')  
data = f.read()   
reg = re.compile('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')    
print ''.join(reg.findall(data))


第4关:http://www.pythonchallenge.com/pc/def/linkedlist.php

会出现无止境的【and the next nothing is 53548】,最后的数字是随机的,需要替换这个数字到url,有点像愚人节的恶作剧

解决方法当然是程序写个循环访问url,大致代码如下:

(期间需要手动更改几次数字,因为提示信息变了。一次是需要将结果除以2,另一次是特意的误导,最终的结果是peak.html)

pre_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
iniDigit = '53548'
while True:    
    try:
        src = urllib2.urlopen(pre_url+str(iniDigit))
        print pre_url+str(iniDigit)
        txt = src.read()
    except Exception,e:
        print e
        print txt
        break
    reg = '\d+'
    regx = re.compile(reg)
    iniDigit = regx.search(txt)
    try:
        iniDigit = iniDigit.group()
    except Exception,e:
        print e
        break
print 'DONE'


第5关:http://www.pythonchallenge.com/pc/def/peak.html

好吧,我承认这道题一点思路也没有,是百度得到的结果

首先,这只有一张图片,下方文件提示是pronounce it,意思就是读它。再看源代码,最底下有行注释peak hell sounds familiar ? 我只想说,不,一点也不familiar,以下是百度结果:

peak hell发音与pickle类似,而pickle是python的一个模块,用于数据持久存储。再看源代码里还有个banner.p文件,其下载下来,并用pickle模块对其进行反序列化,得到一组序列,其中有#,空格和数字。其中数字用于打印空格和数字的次数,最终结果就是一个由#组成的单词图案,代码如下:

import pickle    
if __name__ == '__main__':       
    f = open('banner.p')        
    text = f.read()        
    obj = pickle.loads(text)        
    for list in obj:  
        print(''.join(t[0] * t[1] for t in list))        
    f.close()

第6关:http://www.pythonchallenge.com/pc/def/channel.html

一张拉链图片加一个paypal的链接,查看源代码得知这跟拉链木有关系,但最上方有一行红字特显眼zip,于是将url改成zip.html,错误;改成channel.zip,果然下载到一个.zip文件。里面有一堆txt文件,打开一看,跟第4关惊人地相似啊,只是读url变成读txt文件了,最终找到46145.txt,果然没有那么简单,文件内容是【Collect the comments.】源码和txt里都没有注释,最后看到readme.txt,找到两个提示 hint1: start from 90052 hint2: answer is inside the zip 。好吧,我应该先看这个文件。再次承认,接下来我是百度的了,要用到zipfile这个模块,收集每个txt文件的comment,并且必须从90052开始

最终结果又是字母图标,最终结果是HOCKEY。如果以为答案就是hockey那你就错啦,http://www.pythonchallenge.com/pc/def/hockey.html页面只有一行文件【it's in the air. look at the letters.】,再没有其它信息了。好吧,空气里有什么呢?最多的是氮气,然后是氧气,查了下词典,氧气oxygen帅气登场,就是它了

import zipfile  
import re  

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

第7关:http://www.pythonchallenge.com/pc/def/oxygen.html

待续




0 0
原创粉丝点击