PythonChallenge闯关游戏——第1-5关

第一关:http://www.pythonchallenge.com/pc/def/274877906944.html(-》http://www.pythonchallenge.com/pc/def/map.html)

根据提示,知道这关是一个位移加密,只要将字母都向后移两位,应该就能看到一些什么:

str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
newStr = ""
for c in str:
    if c!=' ' and c!='.' and c!='\'' and c!='(' and c!=')':
        if c == 'y':
            nc = 'a'
        elif c == 'z':
            nc = 'b'
        else:  
            nc = chr(ord(c)+2)
        newStr = newStr + nc
    else:
        newStr = newStr + c
  
print newStr
输出结果:

i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.

看到这结果,虽然知道下关的答案了,但是我用的是一种最笨的方法,有string.maketrans()可以用,百度了该方法的使用,从新写了下:

import string

str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."

table=string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab')
#table=string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:]+string.ascii_lowercase[:2])

print str.translate(table)

将网址map->ocr,即得到下关的url


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

根据提示,我们看下网页源代码:

它让我们找出一大堆乱七八糟的字符中,最小数量的几个,python脚本如下:

dicts = {}
for s in str:
    if dicts.has_key(s):
        dicts[s] = dicts[s] + 1
    else:
        dicts[s] = 1

for k, v in dicts.items():
    print "%s = %d" % (k,v)

str=上面的一大堆乱七八糟的字符,因为太多就不贴在代码里了。

输出结果是:

! = 6079
# = 6115
% = 6104
$ = 6046
& = 6043
) = 6186
( = 6154
+ = 6066
* = 6034
@ = 6157
[ = 6108
] = 6152
_ = 6112
^ = 6030
a = 1
e = 1
i = 1
l = 1
q = 1
u = 1
t = 1
y = 1
{ = 6046
} = 6105

将最少的几个字符整理下,拼出单词equality,得到下一关


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

网页源代码:

再加上标题和提示,我们知道是要用正则来找出xXXXxXXXx这样的模式的字符来,python脚本如下:

import re

f = open('text.txt','r')
data = f.read()

p = re.compile(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')

lists = p.findall(data)
print lists

print "".join(lists)
输出结果:

['l', 'i', 'n', 'k', 'e', 'd', 'l', 'i', 's', 't']
linkedlist

所以得到下一个的url


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

我们打开该网页后只看到了:

linkedlist.php

所以将url改下http://www.pythonchallenge.com/pc/def/linkedlist.php,得到

网页源代码:

点击图片,调整到http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

and the next nothing is 44827

将url再改一下:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=44827

and the next nothing is 45439

从这里就可以知道规律了,要循环取出下一张页面的号码,改换下url,python脚本如下:

import re
import urllib

prefix = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
p = re.compile(r"nothing is (\d+)")
nothing = '12345'
while True:
    text = urllib.urlopen(prefix + nothing).read()
    print text
    lists = p.findall(text)
    if lists:
        nothing = lists[0]
        print "   going to", nothing
    else:
        break

最后一行得到的结果是:

peak.html

所以讲url改下,进入下一关。


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

网页源代码:

根据peak hell的发音和banner.p文件,猜测是pickle,下载banner.p文件并还原得到:

import pickle

openfile = open('banner.p', 'r')
datas = pickle.load(openfile)
print datas
输出结果:

[[(' ', 95)], [(' ', 14), ('#', 5), (' ', 70), ('#', 5), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 6), ('#', 3), (' ', 6), ('#', 4), (' ', 3), ('#', 3), (' ', 9), ('#', 3), (' ', 7), ('#', 5), (' ', 3), ('#', 3), (' ', 4), ('#', 5), (' ', 3), ('#', 3), (' ', 10), ('#', 3), (' ', 7), ('#', 4), (' ', 1)], [(' ', 3), ('#', 3), (' ', 3), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 2), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 1), ('#', 7), (' ', 3), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 3), (' ', 2), ('#', 3), (' ', 5), ('#', 4), (' ', 1)], [(' ', 2), ('#', 3), (' ', 5), ('#', 3), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 3), ('#', 4), (' ', 4), ('#', 5), (' ', 4), ('#', 4), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 5), ('#', 3), (' ', 3), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 4), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 2), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 10), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 5), ('#', 2), (' ', 3), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 10), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 14), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 12), ('#', 4), (' ', 1)], [(' ', 2), ('#', 3), (' ', 6), ('#', 2), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 6), ('#', 2), (' ', 3), ('#', 4), (' ', 1)], [(' ', 3), ('#', 3), (' ', 4), ('#', 2), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 11), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 4), ('#', 3), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1)], [(' ', 6), ('#', 3), (' ', 5), ('#', 6), (' ', 4), ('#', 5), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 6), (' ', 4), ('#', 11), (' ', 4), ('#', 5), (' ', 6), ('#', 3), (' ', 6), ('#', 6)], [(' ', 95)]]

到这里就找不出规律了,百度下,找到接下去的解法:

for j in datas:
    print "".join([i[1] * i[0] for i in j])
结果输出 channel 的图案,通过第五关。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值