The Python Challenge谜题全解(更新至level5)

The Python Challenge 谜题全解

挑战地址:链接: http://www.pythonchallenge.com/

Level 0

很简单,只需计算图片中的 2 38 = ? 2^{38} = ? 238=? 即可

print(2**38)
# 274877906944

Level 1

根据图片提示,每个字母向前移两个单位

ori_text = '''
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.
'''
for s in ori_text:
    if ord('a') <= ord(s) <= ord('z'):
        if ord(s) > ord('z') - 2:
            print(chr(ord(s) - 26 + 2), end='')
        else:
            print(chr(ord(s) + 2), end='')
    else:
        print(s, end='')
# 得到 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.
# 应用到url,得到答案为 ocr

Level 2

根据提示,在网页源代码中找到 rare characters(稀有字符)

import collections
# 由于网页源代码中的字符很长,因此放到了txt文件中读取
ori_text = open('test.txt', mode='r')
content = ori_text.read()
a = collections.Counter(content)
print(a)
# 得到'e': 1, 'q': 1, 'u': 1, 'a': 1, 'l': 1, 'i': 1, 't': 1, 'y': 1,即 equality

Level 3

根据提示,在网页源代码中找到 aAAAaAAAa 格式的字符串,即一个小写字母正好被三个大写字母包围的情形,然后 将所有满足此条件的小写字母组合起来,得到结果

# One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.
file = open('test.txt')
content = file.readlines()
content = [i.strip() for i in content]
for i in range(len(content)):
    for j in range(len(content[i])-9):
        small_letters=content[i][j:j + 9]
        if [s.isupper() for s in small_letters] == [False,True,True,True,False,True,True,True,False]:
            print(small_letters[4],end='')
# 打印得到 linkedlist

Level 4

在网页源代码中找到了 **urllib may help. DON’T TRY ALL NOTHINGS, since it will never
end. 400 times is more than enough. ** 这样的备注提示,但后点击网页中的图片后得到了
这样的链接: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
结合前面的提示,很明显需要循环修改nothing参数访问这个链接

import requests
import re

res = requests.request(url='http://www.pythonchallenge.com/pc/def/linkedlist.php', method='get').content.decode()
first_step = re.findall('<a href="(.*?)">', res)[0]
first_url = 'http://www.pythonchallenge.com/pc/def/' + first_step

count = 0
nothing = '12345'
url,res='',''
while count < 400:
    print(nothing, url, res)
    url = f'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing={nothing}'
    res = requests.request(url=url, method='get').content.decode()
    if re.search('\d+', res):
        nothing = re.search('\d+', res)[0]
        count+=1
    else:
        break
print(nothing,url,res)
# 打印得到 peak.html
# 中途会出现很多陷阱链接,所以建议都打印出来,比如 
'''82683 http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=82682 There maybe misleading numbers in the 
text. One example is 82683. Look only for the next nothing and the next nothing is 63579'''

在这里插入图片描述

Level 5

轻车熟路,对于这种一眼看不懂的图片,我们打开源代码,发现了有一行备注,以及一个 <peakhell>的标签。备注说 sounds familiar ?,那么很可能是一个谐音词,结合py,想到 pickle 库(一般在存储大量数据时会用到,用于将 Python 对象存储到文件中——将 Python 对象序列化为字节流,或从字节流中反序列化为 Python 对象)

<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 ? -->
import pickle
with open('test.pkl', 'r') as file:
    content = file.read()
try:
    deserialized_data_text = pickle.loads(content.encode())
except Exception as e:
    deserialization_error = str(e)

print(deserialized_data_text) if 'deserialized_data_text' in locals() else print(deserialization_error)

反序列后可以发现,这个数据是一个二维list,其中每个内部list包含一系列的元组。每个元组都由一个字符和一个数字组成,这似乎代表了字符的重复次数。

这种数据结构可能用于表示一个二维的字符图案或图像。例如,上面的数据可能表示了一系列的行,其中每行的内容由字符(如空格 ’ ’ 或井号 ‘#’)和重复次数组成。我们或许可以通过这些数据重构原始的字符图像。

image_string = '\n'.join([''.join([char * count for char, count in line]) for line in deserialized_data_text])
print(image_string)
# 得到了下一个关卡 channel

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值