前言:
最近找到一個有關python的游戲闖關,這是游戲中的思考及通關攻略
最開始位於:http://www.pythonchallenge.com/pc/def/0.html
第0關
題目分析
提示hint告訴我們是要嘗試更改URL地址,圖中是2^38,猜測地址是該結果。
考察知識點
- 這是才開始,提示我們網站怎么闖關,以及了解到python中int永遠不會溢出,存在機制自動擴容。
代碼及結果
print(2**38)
輸出:274877906944
下一關:http://www.pythonchallenge.com/pc/def/274877906944.html
第1關
題目分析
注意到字母替換,且K、M、E都是從字母表往后移了2位。學過的就會知道這即是凱撒密碼。
最開始我用的是在線破解網站。破解后,發現可以使用string.maketrans()解決,先用maketrans建立一個映射table,然后使用translate函數
考察知識點
- 字符串的處理,涉及string庫
當然也可以不用string,使用[chr(i) for i in range(97,122)]
來產生字母a-z。
代碼及結果
import string
src = '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 i in range(1,26):
mapping = ''.maketrans(string.ascii_lowercase,string.ascii_lowercase[i:]+string.ascii_lowercase[:i])
print(src.translate(mapping))
輸出: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
下一關:http://www.pythonchallenge.com/pc/def/ocr.html
第2關
題目分析
注意到,左下的信息就是告訴你如何查看上一關的官方答案。
根據紅色提示文字,獲得信息:識別字符,可能在書中,可能在page source(網頁源碼)中
F12查看源碼,可以看到在 body > font > font中看到信息
find rare characters in the mess below,即是要做數據清洗
將需清洗內容復制放入文件‘src/ocr.txt’中,我這是相對路徑,你可以隨便設置,只要自己能打開即可
考察知識點
- 簡單數據清洗,涉及re庫
代碼及結果
import re
with open('src/ocr.txt','r') as f:
s = f.read()
rs = re.findall(r'[a-zA-Z0-9]+',s)
print(''.join(rs))
輸出:equality
下一關:http://www.pythonchallenge.com/pc/def/equality.html
第3關
題目分析
F12查看源碼,在body > font看到:
考察知識點
- 簡單數據清洗,與上一題類似涉及re庫
- 注意到hint,一個小寫字母,兩邊精確的存在3個大寫字母,即是xXXXxXXXx形式,僅取中間一個小寫字母。
也可以使用request爬取網頁源碼。我保存在‘src/equality.txt’中
代碼及結果
import re
with open('src/equality.txt','r') as f:
s = f.read()
rs = re.findall(r'[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]',s,re.S)
print(''.join(rs))
輸出:linkedlist
下一關:http://www.pythonchallenge.com/pc/def/linkedlist.html
第4關
題目分析
-
網頁中只有簡單的文字,linkedlist.php,很自然將其輸入url中跳轉
-
F12網頁title為:follow the chain,提示我們urllib可能還有幫助,且大概要循環400次,下面發現一個可疑的鏈接,打開鏈接:出現下一個數字,一環扣一環如chain,我采用requests爬取,應為網頁簡單只有一個數字,所以不用解析
考察知識點
- requests或者其他爬取庫,re
代碼及結果
import requests,re
def get_src(url):
respon = requests.get(url)
if respon.status_code == 200:
return re.findall(r'\d+',str(respon.content))[0]
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
add = '12345'
count = 0
for i in range(400):
count += 1
add = get_src(url+add)
print(f'{count}:{add}',end = ' ')
異常后,我自需要修改add便可。
輸出:
16044處異常:Yes. Divide by two and keep going.
82683處異常:You've been misleaded to here. Go to previous one and check.
82682處異常:There maybe misleading numbers in the text. One example is 82683. Look only for the next nothing and the next nothing is 63579
66831處異常:peak.html ,其實是進入下一關
下一關:http://www.pythonchallenge.com/pc/def/peak.html
第5關
題目分析
- pronounce it,直翻讀它,F12發現:
banner.p可疑,打開
驚了亂碼,經過學習百度,發現要使用pickle模塊——python對象序列化
save file 后綴為.p
報錯:TypeError: a bytes-like object is required, not 'str'
解釋:由於當前操作的字符串是bytes類型的字符串對象,並對該bytes類型的字符串對象進行按照str類型的操作
解決:open(file,'rb')
pickle.load(file)可以解碼出一個二位列表
是真的鬼,最開始我都沒想到這是字符圖案。。。。。。
最后分析得出:列表中是元組,(字符,個數),分析數據,不難qwq得出解析后得到答案channel
考察知識點
- python的pickle庫
代碼及結果
import pickle
with open('src/banner.p','rb') as f:
data = pickle.load(f)
s = ''
for i in data:
for j in i:
s += j[0]*j[1]
s+='\n'
print(s)
輸出:
下一關:http://www.pythonchallenge.com/pc/def/channel.html
第6關
題目分析
-
嘿嘿,有一個pay,有時候這圖會裂開,有錢人。。。。
-
F12查看源碼發現
即是存在zip文件,下載文件。
我是經過了兩個階段首先沒有使用zipfile。
-
需要收集壓縮文件的注釋 =_=# , 經過一波精彩的操作之后,我知道可以通過zipfile模塊中的z.getinfo('90052.txt').comment得到注釋
最后收集注釋,注意編碼問題,open 只能r/w,
考察知識點
- 文件處理,zizpfile庫
代碼及結果
import zipfile,re
z = zipfile.ZipFile('src/channel.zip')
val = '90052'
count = 0
s = []
try:
while True:
count += 1
print(f'{count}:{val}')
file = f'{val}.txt'
with z.open(file,'r') as f:
s.append(z.getinfo(file).comment)
text = str(f.read(), encoding='UTF-8')
val = re.findall(r'\d+',text)[-1]
except:
s.append(z.getinfo(f'{val}.txt').comment)
print(val)
d = ''
for i in s:
d += str(i,encoding = 'utf-8')
print(d)
輸出:
下一關:http://www.pythonchallenge.com/pc/def/hockey.html
第7關
題目分析
- 我是實在不懂這是什么意思,F12源代碼,請求資源,都沒有信息。最后認真讀這段話后,哈哈哈。TM是氧氣oxygen,強行解釋look air。。。。。
考察知識點
- 腦洞?鬼
代碼及結果
輸出:oxygen
下一關:http://www.pythonchallenge.com/pc/def/oxygen.html
后面還有很多關卡,后續更新。。。。。。