THEPYTHONCHALLENG闯关记录

因为是本身看视频学python,总以为不写几行代码就什么都没有学到。php

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

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

0x00正则表达式

好吧,先来到第0关app

python最好用的地方,计算器ide

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

0x01this

进入第一关url

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

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('\n')
相关文章
相关标签/搜索