The Python Challenge Level-7 Solution

The Python Challenge Level-7 Solution

先附上我在Github上存放的代碼倉庫: The Python Challenge

這道題目網頁源代碼裏沒有什麼別的提示,而圖片中有個條形碼類似物,那麼就需要我們對圖片進行處理了。先想辦法把條形碼讀出來,並且轉換成可讀的文字

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from PIL import Image
from io import BytesIO
import requests

imgUrl = 'http://www.pythonchallenge.com/pc/def/oxygen.png'
img = Image.open(BytesIO(requests.get(imgUrl).content))
for i in range(img.width):
    midPixel = img.getpixel((i,img.height>>1))
    print(midPixel)

得到結果以後我們可以發現,條形碼中沒一條的寬度是7個像素,所以我們可以再處理一下,把相同的條形碼rgb值取一個即可。另外還要注意的是,條形碼沒有覆蓋全部的圖片,最後無序的rgb值需要刪掉,所以改進一下代碼

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'Yuuki_Dach'

from PIL import Image
from io import BytesIO
import requests

imgUrl = 'http://www.pythonchallenge.com/pc/def/oxygen.png'
img = Image.open(BytesIO(requests.get(imgUrl).content))
midPixel = [img.getpixel((i,img.height>>1)) for i in range(0,img.width,7)]
code = [r for r, g, b ,a in midPixel if r==g==b]
print("".join(map(chr,code)))

得到提示

smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]

再對給出的數字進行處理,就能得到‘integrity’

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章