继续挑战!貌似要开始用到图像处理了。
第7题地址oxygen.html
- 网页标题是
smarty
,网页源码中没有隐藏信息
看网页标题是smarty
,自作聪明的人?不懂有什么深层的含义。不过没有其他信息的话,题目应该藏在图中。
这张图中间有一条灰黑色跟条形码类似的东东,怀疑就是类似密码的东西,我们先试着把它提取出来。
from collections import Counter
from io import BytesIO
from itertools import product
import requests
from PIL import Image
response = requests.get('http://www.pythonchallenge.com/pc/def/oxygen.png')
img = Image.open(BytesIO(response.content))
img_data = img.load()
gray_points = {}
c = Counter()
for x, y in product(range(img.width), range(img.height)):
r, g, b, *_ = img_data[x, y]
# 灰点实际上是RGB三通道值相等
if r == g == b:
gray_points[(x, y)] = r
c[y] += 1
print(c)
Counter({43: 608, 44: 608, 45: 608, 46: 608, 47: 608, 48: 608, 49: 608, 50: 608, 51: 608, 11: 19, 12: 19, 13: 19, 14: 19, 15: 18, 16: 17, 35: 6, 36: 6, 37: 6, 38: 6, 30: 5, 31: 5, 27: 5, 25: 5, 22: 5, 19: 5, 32: 4, 33: 4, 34: 4, 28: 4, 29: 4, 26: 4, 23: 4, 24: 4, 21: 4, 20: 4, 18: 4, 17: 4})
通过上述对y坐标方向的灰点数统计,条形码信息应该是在y=43-51
的地方。(回想一下标题,应该说的是smart
y
考虑到每一行的信息应该是相同的,我们只取其中一行看看:
hidden_text = [p[1] for p in gray_points.items() if p[0][1] == 43]
print(hidden_text[:30])
[115, 115, 115, 115, 115, 109, 109, 109, 109, 109, 109, 109, 97, 97, 97, 97, 97, 97, 97, 114, 114, 114, 114, 114, 114, 114, 116, 116, 116, 116]
这些数都在65-122之间,像是英文字母的ASCII码,我们转换一下看看:
print(''.join(chr(i) for i in hidden_text))
sssssmmmmmmmaaaaaaarrrrrrrttttttt ggggggguuuuuuuyyyyyyy,,,,,,, yyyyyyyooooooouuuuuuu mmmmmmmaaaaaaadddddddeeeeeee iiiiiiittttttt....... ttttttthhhhhhheeeeeee nnnnnnneeeeeeexxxxxxxttttttt llllllleeeeeeevvvvvvveeeeeeelllllll iiiiiiisssssss [[[[[[[111111100000005555555,,,,,,, 111111111111110000000,,,,,,, 111111111111116666666,,,,,,, 111111100000001111111,,,,,,, 111111100000003333333,,,,,,, 111111111111114444444,,,,,,, 111111100000005555555,,,,,,, 111111111111116666666,,,,,,, 111111122222221111111]]]]]]]]
有点混乱。我们去除一下重复,用正则就好:
import re
hidden_text = [chr(p[1]) for p in gray_points.items() if p[0][1] == 43]
simplified_text = re.findall(r'(.)\1{4,6}', ''.join(hidden_text))
print(''.join(simplified_text))
smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
好吧,再做一次ASCII码转换:
next_level = re.findall(r'(\d+)', ''.join(simplified_text))
print(''.join(chr(int(i)) for i in next_level))
integrity
将网址改成integrity.html,来到下一题。