The Python Challenge(8)

问题链接

问题链接如下:

http://www.pythonchallenge.com/pc/def/oxygen.html

答案链接

答案链接如下:

http://www.pythonchallenge.com/pc/def/integrity.html

解题思路

页面和源码中无任何提示,但图片中有一条很明显的灰度线,考虑到灰度图取值范围为[0, 255],不妨将其转为ASCII码查看,则有如下代码:

from urllib import request
from PIL import Image

url = 'http://www.pythonchallenge.com/pc/def/oxygen.png'
response = request.urlopen(url)
oxygen = Image.open(response)
oW, oH = oxygen.size
h = oH // 2
msg = ''
# 这里的7来源于:不设置该数字时,输出结果可以看到明显的重复7次。
for w in range(0, oW, 7):
    pixel = oxygen.getpixel((w, h))
    msg  += chr(pixel[0])

print(msg)

输出信息为:

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

将中括号内的数字再次转换为ASCII,则有如下代码:

from urllib import request
from PIL import Image

url = 'http://www.pythonchallenge.com/pc/def/oxygen.png'
response = request.urlopen(url)
oxygen = Image.open(response)
oW, oH = oxygen.size
h = oH // 2
msg = ''
for w in range(0, oW, 7):
    pixel = oxygen.getpixel((w, h))
    msg  += chr(pixel[0])

# print(msg)

s = msg.index('[')
e = msg.index(']')
code = msg[s+1:e].split(',')
for c in code:
    print(chr(int(c)), end='')

print('')

最终输出结果:

integrity

替换原始URL中的对应位置可以得到最终URL为:http://www.pythonchallenge.com/pc/def/integrity.html

你可能感兴趣的:(The Python Challenge(8))