THEPYTHONCHALLENG闯关记录

由于是自己看视频学python,总觉得不写几行代码就什么都没有学到。

找了一个写代码的网站其实只是因为这个看起来好玩

闯关地址http://www.pythonchallenge.com/index.php

0x00

好吧,先来到第0关

python最好用的地方,计算器

2**38算出来答案,在url上修改即可进入下一关

0x01

进入第一关

看到提示,想到要根据图片中的提示得到转换方法,解密提示,显然不只有三种方法,而是每一个字符都右移两位,我还没有学到映射,就用了暴力转换(先全部变成大写)。

1 a = "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."
2 a=a.upper()
3 for i in range(26):
4     a=a.replace(chr(65+i),chr(97+(i+2)%26))
5 print(a)

一开始不知道字符串内的方法是生成一个备份,调了半天,(((φ(◎ロ◎;)φ)))

map()真香,重构了一下代码,舒服多了

1 a="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."
2 def func(ch):
3     if ord(ch)>=97 and ord(ch)<=122:
4         return chr(97+(ord(ch)-97+2)%26)
5     else:
6         return ch
7 b="".join(list(map(func,a)))
8 print(b)

解密得到"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."

将上述规则应用于map,得到ocr,即可进入下一关

0x02

根据说明,找到源码

<!--
find rare characters in the mess below:
-->

随便试了一下,发现出现次数最少的是一次,还是字母,就想到如果把所有的出现次数为一次的字母都按顺序找到,就可以得到答案了。

filter()真香

1 b="".join(list(filter(lambda ch : a.count(ch)==1,a)))
2 print(b)

0x03

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

要找的是被恰好三个大写字母夹着的小写字母

我想到了遍历

 1 l=len(a)
 2 def func(x):
 3     if x >= 4 and x <= l - 5:
 4         if 97 <= ord(a[x]) <= 122:
 5             flg=True
 6             for i in range(3):
 7                 if not (65 <= ord(a[x - i - 1]) <= 90 and 65 <= ord(a[x + i + 1]) <= 90):
 8                     flg=False
 9             if flg:
10                 return 97<=ord(a[x-4])<=122 and 97<=ord(a[x+4])<=122
11 b = list(filter(func, range(l)))
12 c=[]
13 for i in b:
14     c.append(a[i])
15 print("".join(c))

读完题解,啊,我居然忘了isupper(),题解NB

 1 lst=[""]*9
 2 ans=''
 3 for i in a:
 4     del lst[0]
 5     lst.append(i)
 6     if lst[0].islower()
 7     and lst[1].isupper()
 8     and lst[2].isupper()
 9     and lst[3].isupper()
10     and lst[4].islower()
11     and lst[5].isupper()
12     and lst[6].isupper()
13     and lst[7].isupper()
14     and lst[8].islower()
15     :
16         ans += lst[4]
17 print(ans)

一开始看到linkedlist.php我是懵逼的,觉得这个很想正确答案,却进不了下一关,卡了很久,把html改成php就可以过了,(((φ(◎ロ◎;)φ)))、

0x04

点进图片之后看到了and the next nothing is 44827

就知道将url最后的数字改为44827,之后是45439,结果得到提示Your hands are getting tired and the next nothing is 94485

根据题目为链表就知道需要把根据提示不断修改url,从而得到key

首先读取内容,之后修改url,并一直重复,读取内容一开始想着可不可以每次截取最后的5位,后来发现可能存在不是5位的数字,想到了正则表达式,每次匹配字符串末尾的数字,虽然实现了,但是需要人工控制程序停止,看到题解可以每次匹配and the next nothing is这个字符串,用到了re中的search,这确实是之前不曾注意到的。不知不觉,就把代码改成了题解的样子qwq

from urllib import request
import re
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
num = '12345'
mdl = re.compile(r'and the next nothing is (d*)').search
while True:
    with request.urlopen(url+num) as f:
        x = str(f.read(),encoding = 'utf-8')
        print(x)
        match = mdl(x)
        if match:
            num = match.group(1)
        else:
            if x == 'Yes. Divide by two and keep going.':
                num = str(int(num)/2)
            else:
                break

 0x05

图片下方有提示,pronounce it(是不是读着像pickle

在网页源代码中可以找到一个banner.p文件,将它反序列化得到一个列表,再将列表中的元素按行打印,即可得到结果(我的脑洞还是不够大啊啊啊啊啊啊

import pickle
with open('banner.p','rb') as f:
    data = pickle.load(f)
for i in data:
    for j in i:
        for k in range(j[1]):
            print(j[0],end='')
    print('
')
原文地址:https://www.cnblogs.com/fantasquex/p/10137088.html