有趣的Python Challenge编程解谜游戏闯关攻略二(5-9关)

**有趣的Python Challenge编程解谜游戏闯关攻略二(5-9关)**

介绍

游戏介绍

平时自己学python,大家肯定很是无聊,推荐一个很早之前的网页版python闯关游戏——Python Challenge,虽然说这个网站很早了,但是很有意思,你会发现这些游戏一点也不简单,基本都需要通过编程来解决……

有意思的是,这是个解谜游戏,所以需要你细心去发现线索,破解谜底,并且考察的知识量也不是很小,很有意思。

游戏链接:http://www.pythonchallenge.com/

界面是这样的:

点击图中Click here to get challenged开始挑战。

0-4关攻略

(0-4关攻略:点击这里直接查看

写在前面

从第五关起,后面的关卡都是比较难的,但是我们是站在巨人的肩膀上的,我们可以参考前人智慧。
另外,其实每一关的网页标题都是有一定的提示作用的,注意查看。

关卡

第5关

在这里插入图片描述
提示pronounce it,貌似没头绪,查看源代码:

<html>
<head>
  <title>peak hell</title>
  <link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<center>
<img src="peakhell.jpg"/>
<br><font color="#c0c0ff">
pronounce it
<br>
<peakhell src="banner.p"/>
</body>
</html>
<!-- peak hell sounds familiar ? -->

可以看见注释<!-- peak hell sounds familiar ? -->读起来熟悉吗??其实就是pickle库,得到URL:http://www.pythonchallenge.com/pc/def/pickle.html进去之后发现一句话yes! pickle!,看来方向没错,但是没用。
网页标题是peak hell,网页源代码也有个peakhell标签,http://www.pythonchallenge.com/pc/def/banner.p看看再说,像是这样,看不懂:在这里插入图片描述
看来需要pickle了,上代码:

import pickle
from urllib.request import urlretrieve
url = 'http://www.pythonchallenge.com/pc/def/banner.p'
urlretrieve(url, filename = 'five.pkl')
with open('five.pkl', 'rb') as f:
    r = pickle.load(f)

结果是这样的

[(' ', 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)]]

看来数字应该是代表字符的数量,改变代码:

from urllib.request import urlretrieve
import pickle
url = 'http://www.pythonchallenge.com/pc/def/banner.p'
urlretrieve(url, filename = 'five.pkl')
with open('five.pkl', 'rb') as f:
    r = pickle.load(f)
for i in r:
    for j in i:
        print(j[0] * j[1], end = '')
    print('\n')

打印结果比较令人惊喜,是这样的

                                                                                               

              #####                                                                      ##### 

               ####                                                                       #### 

               ####                                                                       #### 

               ####                                                                       #### 

               ####                                                                       #### 

               ####                                                                       #### 

               ####                                                                       #### 

               ####                                                                       #### 

      ###      ####   ###         ###       #####   ###    #####   ###          ###       #### 

   ###   ##    #### #######     ##  ###      #### #######   #### #######     ###  ###     #### 

  ###     ###  #####    ####   ###   ####    #####    ####  #####    ####   ###     ###   #### 

 ###           ####     ####   ###    ###    ####     ####  ####     ####  ###      ####  #### 

 ###           ####     ####          ###    ####     ####  ####     ####  ###       ###  #### 

####           ####     ####     ##   ###    ####     ####  ####     #### ####       ###  #### 

####           ####     ####   ##########    ####     ####  ####     #### ##############  #### 

####           ####     ####  ###    ####    ####     ####  ####     #### ####            #### 

####           ####     #### ####     ###    ####     ####  ####     #### ####            #### 

 ###           ####     #### ####     ###    ####     ####  ####     ####  ###            #### 

  ###      ##  ####     ####  ###    ####    ####     ####  ####     ####   ###      ##   #### 

   ###    ##   ####     ####   ###########   ####     ####  ####     ####    ###    ##    #### 

      ###     ######    #####    ##    #### ######    ###########    #####      ###      ######

看起来是个单词channel,至此我们得到了结果:

http://www.pythonchallenge.com/pc/def/channel.html

第6关

在这里插入图片描述
页面出现的Donate,其实就是字面意思,查看源代码有注释如下:
其实就是作者在拉赞助,跟题目毫无关系……

<!-- 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.

-thesamet
-->

其实源代码中还有一句注释<!-- <-- zip -->图片的拉链也是zip,应该方向没错,其实他的另外的意思是提示压缩包,http://www.pythonchallenge.com/pc/def/channel.zip访问链接就能下载压缩包。
打开以后,里面有九百多的txt文件,大概看一下,最后一个是read me,打开以后如下,看来是和第四题差不多。

welcome to my zipped list.

hint1: start from 90052
hint2: answer is inside the zip

编程解决:

import zipfile as zi

path = "C:\\Users\\sky\\Desktop\\channel.zip"

# 使用 zipfile 包解压并读取文件内容到 files
files = {}
fzip = zi.ZipFile(path)
for name in fzip.namelist():
    with fzip.open(name) as fz:
        files[name] = fz.read().decode("utf-8")

# readme.txt 中 nothing 初始值
nothing = "90052"
while True:
    f = nothing + ".txt"
    strs=str(files[f])
    print(strs)
    try:
        nothing = strs.split()[-1]
    except:
        break

输出结果是这样

此处省略n行
Next nothing is 67824
Next nothing is 46145
Collect the comments.

提示收集comments,去哪里找呢,还是在库中找信息吧???
其实上面的代码虽然能输出结果,但是在解决下面的问题的时候有一定的问题,下面我们进行改正:

import re
上面的代码
while True:
    fz = nothing + ".txt"
    # 获取 comment 并输出
    print(fzip.getinfo(fz).comment.decode("utf-8"), end="")
    if fz in files:
        # print(files[fz])
        result = re.search(r"Next nothing is (\d+)", files[fz])
        try:
            nothing = result.group(1)
        except:
            break

结果是这样

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

显然是单词hockey,得到链接http://www.pythonchallenge.com/pc/def/hockey.html
打开之后提示it's in the air. look at the letters.在空气中,看字母,,看到了吗?
上面的结果组成是 O X Y G E N,显然,这是氧气,所以得到答案:

http://www.pythonchallenge.com/pc/def/oxygen.html

第7关

在这里插入图片描述
比较奇怪,没有明显提示,源代码也没有提示,看来在图片本身,图片中间比较奇怪,马赛克吧好像。使用PIL处理图像,貌似马赛克在中间,编程如下:

from PIL import Image 
im = Image.open("oxygen.png")  #文件路径
width, height = im.size  # 获取尺寸
pic = im.load()
h = height // 2
for x in range(width):  
    print(pic[x,h])

结果

省略……
(97, 97, 97, 255)
省略……
(100, 100, 100, 255)
省略……
省略……
(116, 116, 116, 255)
省略……

可以看见R,G,B是一样的,目测可能是ASCII码,

from PIL import Image 
im = Image.open("oxygen.png")  #文件路径,如果没有路径就是当前目录下文件
width, height = im.size  # 获取图像尺寸
pic = im.load()
h = height // 2
ss=0  ##ss是我随便定义一个中间变量,用来存储上一次的值
for x in range(width):
    r, g, b, x = pic[x, h]
    if r != g:
        continue
    if ss!=r:
        print(chr(r), end='')
    ss=r

打印结果是

smart guy, you made it. the next level is [105, 10, 16, 101, 103, 14, 105, 16, 121]

很明显了,继续干

answer = [105, 110, 116, 101, 103, 114, 105, 116, 121]
for l in answer:
    print(chr(l), end='')

输出integrity。 得到url:
http://www.pythonchallenge.com/pc/def/integrity.html

第8关

在这里插入图片描述
点击蜜蜂,提示需要输入用户名和密码。查看源代码

<!--
un: 'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'
pw: 'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08'
-->

搜索 BZh91AY&SY,发现是 bz2 编码结果。搜索结果

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"))

输出结果

huge
file

点击蜜蜂登陆就可以了。
新的url:http://www.pythonchallenge.com/pc/return/good.html

第9关

在这里插入图片描述
让我们连接点,但是黑点连起来也看不出来啥。查看源代码,有用的注释:

<!--
first+second=?

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

-->

也许这才是真正的需要连接的点的坐标。

from PIL import Image, ImageDraw

first = [数据]
second = [数据]
img = Image.open('good.jpg')#文件路径

draw = ImageDraw.Draw(img)
draw.line(first, fill=255)
draw.line(first, fill=255)
img.show()

结果是这样
在这里插入图片描述
一头牛???试试常见的bull (公牛)。正确了得到新的url:

 http://www.pythonchallenge.com/pc/return/bull.html

其实尝试 cow (母牛)的时候会有提示

hmm. it's a male.

链接总结

0-4关:https://blog.csdn.net/weixin_46283214/article/details/105345260
5:http://www.pythonchallenge.com/pc/def/channel.html
6:http://www.pythonchallenge.com/pc/def/oxygen.html
7:http://www.pythonchallenge.com/pc/def/integrity.html
8:http://www.pythonchallenge.com/pc/return/good.html
9:http://www.pythonchallenge.com/pc/return/bull.html

第10关预告

a = [1, 11, 21, 1211, 111221, 

???找规律……

发布了4 篇原创文章 · 获赞 8 · 访问量 461

猜你喜欢

转载自blog.csdn.net/weixin_46283214/article/details/105389166