因爲是本身看視頻學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')