0%

Python Challenge (Level 27)

第27关

点击图片,提示输入用户名和密码,看来这一关就是要找到用户名和密码。

根据Page Source的提示,很容易得到zigzag.gif

这张图片上每个像素值是调色板的索引,将每一个像素替换为调色板中相应的颜色。

1
2
3
4
5
6
im = Image.open('zigzag.gif')
imdata = im.tostring()
p = im.palette.getdata()[1][::3] #RGB相等,因此每三个取一个
frm = ''.join([chr(i) for i in range(256)])
table = string.maketrans(frm, p)
imdata_trans = imdata.translate(table)

查看一下前二十个字节会发现,imdata和imdata_trans很相似。

1
2
3
4
5
imdata[:20]
"\xd7\xd0\xcb\x0c\xfe<\x8bHB\xbd\x7f\xb0\xadF\xaa\xcf' ~\x8e"

imdata_trans[:20]
"\xd0\xcb\x0c\xfe<\x8bHB\xbd\x7f\xb0\xadF\xaa\xcf' ~\x8e\xa4"

将两者对齐,记录不同之处的坐标以及相应内容。坐标信息会形成一幅图片,不同的内容则是一串压缩的字符串,解压后得到许多Python关键字。

1
2
3
4
5
6
7
8
newIm = Image.new('1', im.size)
newIm.putdata([i[0] == i[1] for i in zip(imdata[1:], imdata_trans[:-1])])
newIm.save('out27.png')
#这里有点奇怪,直接show()得到的是全黑图像。要用save才有内容

diff = filter(lambda p: p[0] != p[1], zip(imdata[1:], imdata_trans[:-1]))
diff = [''.join(p[i] for p in diff) for i in range(2)]
text = bz2.decompress(diff[0])

根据得到图片的提示no keyword,将得到的text里面的非Python keyword提出来。

1
2
3
4
5
6
7
8
words = text.split(' ')
for w in set(words):
if not keyword.iskeyword(w):
print w

switch
repeat
../ring/bell.html

switch/repeat即为用户名和密码 http://www.pythonchallenge.com/pc/ring/bell.html

参考文章