上文介绍了Python Challenge第0至5关的通关攻略及代码,从第6关开始解谜难度开始上升,本文继续介绍第6至10关的通关攻略及代码。
第6关:now there are pairs
url:http://www.pythonchallenge.com/pc/def/channel.html
6.1 攻略
-
结合界面显示图片和源代码,发现源代码中提示zip。
-
尝试将url修改为http://www.pythonchallenge.com/pc/def/zip.html,界面提示“yes. find the zip.”
但是此页面并无zip文件。
-
尝试修改url为http://www.pythonchallenge.com/pc/def/channel.zip,下载得到压缩文件channel.zip,压缩文件中的readme文件给了2个提示:从90052文件开始寻找,答案就在这个zip中。
-
剩余思路类似第4关(follow the chain),循环查找文件,区别在于第4关使用urllib访问网页,本关使用zipfile读取文件。读取文件得到提示要获取comment信息,因此调用ZipFile.getinfo方法获取comment信息,得到“hockey”,修改url为http://www.pythonchallenge.com/pc/def/hockey.html
-
http://www.pythonchallenge.com/pc/def/hockey.html界面中提示“it’s in the air. look at the letters.”,观察上述代码输出结果,发现由O、X、Y、G、E、N组成,恰好为“oxygen”(空气中的氧气),因此修改url为http://www.pythonchallenge.com/pc/def/oxygen.html进入第7关。
6.2 代码
from zipfile import ZipFile
res = []
with ZipFile('channel.zip') as z:
filename = '90052.txt'
while True:
if filename in z.namelist():
res.append(z.getinfo(filename).comment.decode('utf-8'))
with z.open(filename) as f:
s = f.read().decode('utf-8')
filename = s.split()[-1] + '.txt'
else:
print(s)
break
print(''.join(res))
输出:
第7关:smarty
url:http://www.pythonchallenge.com/pc/def/oxygen.html
7.1 攻略
可以看到第7关界面上图片的中间有一条马赛克条带,因此尝试读取该条带的像素值,发现马赛克条带的像素值前3位相同,将其转换为ASCII值后,得到提示“smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]”。然后再将 [105, 110, 116, 101, 103, 114, 105, 116, 121] 转换为ASCII值后得到答案integrity,因此修改url为http://www.pythonchallenge.com/pc/def/integrity.html进入第8关。
7.2 代码
from PIL import Image
im = Image.open('oxygen.png')
pix = im.load()
width, height = im.size
result = []
for i in range(width):
r, g, b, x = pix[i, height // 2]
if r == g and i % 7 == 0:
result.append(chr(r))
#输出提示,得到level数组
print(''.join(result))
level = [105, 110, 116, 101, 103, 114, 105, 116, 121]
print(''.join([chr(i) for i in level]))
输出:
第8关:working hard?
url:http://www.pythonchallenge.com/pc/def/integrity.html
8.1 攻略
- 界面下方有一个灰色的提示“Where is the missing link?”,因此寻找隐藏的链接,查看源代码发现图片中包含隐藏的链接,点击跳转至http://www.pythonchallenge.com/pc/return/good.html,如下图所示,该界面要输入用户名和密码进行登录。
- 刚好上级页面的源代码中包含用户名和密码的相关提示,如下图所示,un和pw均为bz2加密串,因此使用bz2解码后即得到用户名huge和密码file,登录成功进入下一关。该密码需要保存,后面几关还会用到。
8.2 代码
import bz2
un = b'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'
pw = b'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08'
print(bz2.decompress(un).decode("utf-8"))
print(bz2.decompress(pw).decode("utf-8"))
# Output:
# huge
# file
第9关:connect the dots
url:http://www.pythonchallenge.com/pc/return/good.html
9.1 攻略
-
界面上有好多黑点,关卡名“connect the dots”提示将点连接起来,查看源代码发现点的坐标,如下图所示。
-
由于first和second的长度明显不同,无法形成(first[i], second[i])形式的坐标,故尝试分别将first和second中的元素两两组合形成坐标,使用matplotlib画散点图,发现图像是一只牛,猜测答案为cow,修改url为http://www.pythonchallenge.com/pc/return/cow.html,得到提示“hmm. it’s a male.”。
-
这说明答案为公牛bull,修改url为http://www.pythonchallenge.com/pc/return/bull.html进入第11关。
9.2 代码
import matplotlib.pyplot as plt
first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,329,170,320,170,\
310,171,301,173,290,178,289,182,287,188,286,190,286,192,291,194,296,195,305,194,307,191,312,190,316,\
190,321,192,331,193,338,196,341,197,346,199,352,198,360,197,366,197,373,196,380,197,383,196,387,192,\
389,191,392,190,396,189,400,194,401,201,402,208,403,213,402,216,401,219,397,219,393,216,390,215,385,\
215,379,213,373,213,365,212,360,210,353,210,347,212,338,213,329,214,319,215,311,215,306,216,296,218,\
290,221,283,225,282,233,284,238,287,243,290,250,291,255,294,261,293,265,291,271,291,273,289,278,287,\
279,285,281,280,284,278,284,276,287,277,289,283,291,286,294,291,296,295,299,300,301,304,304,320,305,\
327,306,332,307,341,306,349,303,354,301,364,301,371,297,375,292,384,291,386,302,393,324,391,333,387,\
328,375,329,367,329,353,330,341,331,328,336,319,338,310,341,304,341,285,341,278,343,269,344,262,346,\
259,346,251,349,259,349,264,349,273,349,280,349,288,349,295,349,298,354,293,356,286,354,279,352,268,\
352,257,351,249,350,234,351,211,352,197,354,185,353,171,351,154,348,147,342,137,339,132,330,122,327,\
120,314,116,304,117,293,118,284,118,281,122,275,128,265,129,257,131,244,133,239,134,228,136,221,137,\
214,138,209,135,201,132,192,130,184,131,175,129,170,131,159,134,157,134,160,130,170,125,176,114,176,\
102,173,103,172,108,171,111,163,115,156,116,149,117,142,116,136,115,129,115,124,115,120,115,115,117,\
113,120,109,122,102,122,100,121,95,121,89,115,87,110,82,109,84,118,89,123,93,129,100,130,108,132,110,\
133,110,136,107,138,105,140,95,138,86,141,79,149,77,155,81,162,90,165,97,167,99,171,109,171,107,161,\
111,156,113,170,115,185,118,208,117,223,121,239,128,251,133,259,136,266,139,276,143,290,148,310,151,\
332,155,348,156,353,153,366,149,379,147,394,146,399]
second = [156,141,165,135,169,131,176,130,187,134,191,140,191,146,186,150,179,155,175,157,168,157,163,157,159,\
157,158,164,159,175,159,181,157,191,154,197,153,205,153,210,152,212,147,215,146,218,143,220,132,220,\
125,217,119,209,116,196,115,185,114,172,114,167,112,161,109,165,107,170,99,171,97,167,89,164,81,162,\
77,155,81,148,87,140,96,138,105,141,110,136,111,126,113,129,118,117,128,114,137,115,146,114,155,115,\
158,121,157,128,156,134,157,136,156,136]
x = []
y = []
for i in range(len(first)):
if i % 2 == 0:
y.append(first[i])
else:
x.append(first[i])
for j in range(len(second)):
if j % 2 == 0:
y.append(second[j])
else:
x.append(second[j])
plt.scatter(x, y)
plt.show()
输出:
第10关:what are you looking at?
url:http://www.pythonchallenge.com/pc/return/bull.html
10.1 攻略
- 界面下方谜题为len(a[30]) = ?,界面中两只牛,一只牛直勾勾地看着你,关卡名称是“what are you looking at?”,猜测该牛身上可能有提示信息,鼠标移到牛身上发现链接点击跳转至http://www.pythonchallenge.com/pc/return/sequence.txt,得到数组a的前5项1, 11, 21, 1211, 111221
- 观察数组a发现规律:
11:前一项是1,依次包含1个1;
21:前一项是11,依次包含2个1;
1211:前一项为21,依次包含1个2,1个1;
111221:前一项为1211,依次包含1个1,1个2,2个1;
因此,编程求解a[30]的长度,得到5808,修改url为http://www.pythonchallenge.com/pc/return/5808.html进入第11关。
10.2 代码
prev_elem = '1'
curr_elem = ''
for i in range(30):
j = 0
k = 0
while j < len(prev_elem):
while k < len(prev_elem) and prev_elem[k] == prev_elem[j]:
k += 1
curr_elem += str(k - j) + prev_elem[j]
j = k
prev_elem = curr_elem
curr_elem = ''
print(len(prev_elem))
# Output: 5808
以上就是Python Challenge第6-10关攻略啦,第11-15关攻略请见文章Python Challenge通关攻略及代码(第11至15关)~
完整代码及运行结果详见: