The Python Challenge 闖關筆記


The Python Challenge : http://www.pythonchallenge.com/

Level 0:

看提示圖片中為2**38,計算值為274877906944。

Hint: try to change the URL address.

下一關地址:http://www.pythonchallenge.com/pc/def/274877906944.html

 

Level 1:

Hint 1:K->M  O->Q  E->G

此提示可看出是位移計算,都是位移兩位

Hint 2: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.

想必是利用Hint 1的唯一算法轉換字符串,得到下一關的地址信息,需要注意的是轉換是在26個字母中轉換的,不多說,上代碼

s = "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."
def change_str(s):
    if s is 'y':
        return 'a'
    if s is 'z':
        return 'b'
    if s.isalpha() and s not in 'yz':
        return chr(ord(s)+2)
    return s

ns = map(change_str, s)
print ''.join(ns)

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

 

Level 2:

根據提示密碼藏在圖片的書中,或者頁面源碼中,看了下圖片果斷F12,看到頁面源碼中有一大段字符串,提示找出重復最少的

import collections
def mycount(s):
    lit = []
    lit_num = []
    for item in s:
        if item in lit:
            continue
        lit.append(item)
    for item in lit:
        num = s.count(item)
        lit_num.append(num)
    return collections.OrderedDict(zip(lit, lit_num))

dic = mycount(s)
for k, v in dic.iteritems():
    print k, '=', v

由於字符是有順序的,所以這里我使用了有序的字典,進行存儲字符跟出現次數,得到結果為;equality

下一關地址:http://www.pythonchallenge.com/pc/def/equality.html

 

Level 3:

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

找到這么一個小寫字母,兩邊都是三個大寫字母,要求:xXXXxXXXx

兩邊都是連續的三個大寫字母,所以再邊上就要是小寫字母,不然就不滿足要求了

在哪里找這些字符呢??查看頁面源碼,發現有一大串字符串,一定是在這里找了。

使用正則表達式進行查找字符串,附上代碼:

regex = r"[^A-Z][A-Z]{3}[a-z][A-Z]{3}[^A-Z]"
REGEX = re.compile(regex)
result = REGEX.findall(s)
print result

得到:['qIQNlQSLi', 'eOEKiVEYj', 'aZADnMCZq', 'bZUTkLYNg', 'uCNDeHSBj', 'kOIXdKBFh', 'dXJVlGZVm', 'gZAGiLQZx', 'vCJAsACFl', 'qKWGtIDCj']

 取的小寫字母得:linkedlist

訪問:http://www.pythonchallenge.com/pc/def/linkedlist.html,得到linkedlist.php

下一關地址:http://www.pythonchallenge.com/pc/def/linkedlist.php

 

Level 4:

點擊圖片跳轉頁面顯示:and the next nothing is 44827

 查看頁面源碼發現: urllib may help. DON'T TRY ALL NOTHINGS, since it will never
end. 400 times is more than enough.

嘗試把nothing改為44827,頁面跳轉顯示:and the next nothing is 45439

根據提示應該是要一直訪問,訪問400次就的到下一關頁面

import urllib
from bs4 import BeautifulSoup

def challenge(noth):
    url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing={}".format(noth)
    responce = urllib.urlopen(url)
    html = responce.read()
    soup = BeautifulSoup(html, 'lxml')
    body_text = soup.find('body').text
    nothing = (body_text.split('.')).pop()
    if 'html' == nothing:
        print 'Congratulations!!!!-----------------------------------------------'
        print body_text
    else:
        print '-----------------------------------------------------------------'
        print body_text
        nothing = (body_text.split(' ')).pop()
        try:
            if isinstance(int(nothing), int):
                return challenge(nothing)
        except ValueError:
            nothing = int(noth) / 2
            print nothing
            print '--------------------------------------------------------------'
            return challenge(nothing)

 

查看記錄得到:peak.html

下一關地址:http://www.pythonchallenge.com/pc/def/peak.html

 

Level 5:

這題有點坑爹,找不到突破點,百度了下,根據發音的到需要用pickle處理數據,暈....

查看源碼,下載banner.p,打開看了下,確實像是pickle處理過的,使用pickle處理得到

[[(' ', 95)], [(' ', 14), ('#', 5), (' ', 70), ('#', 5), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 6), ('#', 3), (' ', 6), ('#', 4), (' ', 3), ('#', 3), (' ', 9), ('#', 3), (' ', 7), ('#', 5), (' ', 3), ('#', 3), (' ', 4), ('#', 5), (' ', 3), ('#', 3), (' ', 10), ('#', 3), (' ', 7), ('#', 4), (' ', 1)], [(' ', 3), ('#', 3), (' ', 3), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 2), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 1), ('#', 7), (' ', 3), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 3), (' ', 2), ('#', 3), (' ', 5), ('#', 4), (' ', 1)], [(' ', 2), ('#', 3), (' ', 5), ('#', 3), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 3), ('#', 4), (' ', 4), ('#', 5), (' ', 4), ('#', 4), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 5), ('#', 3), (' ', 3), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 4), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 2), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 10), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 5), ('#', 2), (' ', 3), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 10), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 14), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 12), ('#', 4), (' ', 1)], [(' ', 2), ('#', 3), (' ', 6), ('#', 2), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 6), ('#', 2), (' ', 3), ('#', 4), (' ', 1)], [(' ', 3), ('#', 3), (' ', 4), ('#', 2), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 11), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 4), ('#', 3), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1)], [(' ', 6), ('#', 3), (' ', 5), ('#', 6), (' ', 4), ('#', 5), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 6), (' ', 4), ('#', 11), (' ', 4), ('#', 5), (' ', 6), ('#', 3), (' ', 6), ('#', 6)], [(' ', 95)]]

看到元組的第一個元素不是空格就是#,第二個元素可能是個數,嘗試了下

import pickle
f = open('banner.p')

l = pickle.load(f)
print l
print '\n'.join([''.join([p[0] * p[1] for p in item]) for item in l])

for item in l:
    for p in item:
        s = p[0] * p[1]

f.close()

果真是一幅圖

              #####                                                                      ##### 
               ####                                                                       #### 
               ####                                                                       #### 
               ####                                                                       #### 
               ####                                                                       #### 
               ####                                                                       #### 
               ####                                                                       #### 
               ####                                                                       #### 
      ###      ####   ###         ###       #####   ###    #####   ###          ###       #### 
   ###   ##    #### #######     ##  ###      #### #######   #### #######     ###  ###     #### 
  ###     ###  #####    ####   ###   ####    #####    ####  #####    ####   ###     ###   #### 
 ###           ####     ####   ###    ###    ####     ####  ####     ####  ###      ####  #### 
 ###           ####     ####          ###    ####     ####  ####     ####  ###       ###  #### 
####           ####     ####     ##   ###    ####     ####  ####     #### ####       ###  #### 
####           ####     ####   ##########    ####     ####  ####     #### ##############  #### 
####           ####     ####  ###    ####    ####     ####  ####     #### ####            #### 
####           ####     #### ####     ###    ####     ####  ####     #### ####            #### 
 ###           ####     #### ####     ###    ####     ####  ####     ####  ###            #### 
  ###      ##  ####     ####  ###    ####    ####     ####  ####     ####   ###      ##   #### 
   ###    ##   ####     ####   ###########   ####     ####  ####     ####    ###    ##    #### 
      ###     ######    #####    ##    #### ######    ###########    #####      ###      ######

坑爹!坑爹!

下一關地址:http://www.pythonchallenge.com/pc/def/channel.html

 

Level 6:

Hint:查看頁面源碼,發現注釋zip,可能與Zip文件有關

將channel.html改為channel.zip,還真有zip文件;

打開zip文件,看到有個readme.txt,內容如下:

welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip
發現其他文件名都是數字,於是采用zipfile模塊處理文件,獻上代碼:

import zipfile

file_zip = zipfile.ZipFile('channel.zip')
files = file_zip.namelist()
def item(start):

    if start in files:
        with file_zip.open(start) as f:
            content = f.read()
            print content
            result = '{}.txt'.format(content.split(' ').pop())
        return item(result)
    else:
        result = start.split('.')
        print 'The result is: ', result[0]

if __name__ == '__main__':
    item('90052.txt')
   

程序最后得到:Collect the comments.

comment??哪里來的comment,想到可能是文件的,查看到zipfile有個comment屬性

於是修改程序,收集每個文件的comment,

import zipfile

file_zip = zipfile.ZipFile('channel.zip')
files = file_zip.namelist()
lst = []
def item(start):

    if start in files:
        with file_zip.open(start) as f:
            content = f.read()
            com = file_zip.getinfo(start).comment
            lst.append(com)
            print content
            result = '{}.txt'.format(content.split(' ').pop())
        return item(result)
    else:
        result = start.split('.')
        print 'The result is: ', result[0]

if __name__ == '__main__':
    item('90052.txt')
    result = ''.join(lst)
    print result

得到:

****************************************************************
****************************************************************
**                                                            **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE NN      NN  **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE  NN    NN   **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE       NN  NN    **
**   OOOOOOOO XX    XX YY        GGG       EEEEE     NNNN     **
**   OOOOOOOO XX    XX YY        GGG       EEEEE      NN      **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE         NN      **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE     NN      **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE     NN      **
**                                                            **
****************************************************************
 **************************************************************

訪問:http://www.pythonchallenge.com/pc/def/hockey.html

得到:it's in the air. look at the letters.

還沒完成,看到comments里有些字母,“OXYGEN”,將hockey改為oxygen得帶下一關地址

下一關地址:http://www.pythonchallenge.com/pc/def/oxygen.html

 

 

持續更新

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM