Python Challenge[27]

[Level 27]


Title: between the tables

图片链向的地址即是下一关的url,但是需要用户名和密码。从源码提示did you say gif?下载到zigzag.gif。查看了图片的各属性,没有头绪。

或许我们先要知道什么是 [palette] [p1],嗯,[调色板] [p2],或者[更详细的调色板] [p3]。
[p1]: https://en.wikipedia.org/wiki/Palette_(computing)
[p2]: https://zh.wikipedia.org/wiki/BMP#.E8.B0.83.E8.89.B2.E6.9D.BF
[p3]: http://www.360doc.com/content/10/0928/15/2790922_57060786.shtml

调色板相当于建立了颜色索引,我们要把它们还原颜色。

from PIL import Image
img = Image.open('zigzag.gif')
data = img.tobytes()
p = img.getpalette()[::3]
table = bytes.maketrans(bytes([i for i in range(256)]),bytes(p))
trans = data.translate(table)

对齐转换前后的数据,找出不同:

zipped = list(zip(data[1:],trans[:-1]))
indices = [i for  i,p in enumerate(zipped) if p[0]!=p[1]]
new = Image.new(img.mode,img.size)
color = [255,]*len(data)
for i in indices:
  color[i] = 0
new.putdata(color)
new.show()

显示:


notword,中间有一把钥匙-key。然而并不是下一关的钥匙。“不同”组成的信息呢?

import bz2
import keyword
diff = [p[0] for p in zipped if p[0]!=p[1]]
text = bz2.decompress(bytes(diff)).decode()
print(set(i for i in text.split() if not keyword.iskeyword(i)))

打印出:

{'switch', 'repeat', 'exec', 'print', '../ring/bell.html'}

repeatswitch 才是用户名和密码,[Level 28]

小结

或者这样找diff:
diff = list(filter(lambda p: p[0] != p[1], zipped))

  1. [Image.getpalette()] [s1] 返回调色板列表数据。
  2. [enumerate(iterable, start=0)] [s2] 将可迭代对象做成索引序列。
  3. [zip()] [s3] 接受可迭代对象,将对应的元素打包再组成新的可迭代对象。
  4. [keyword.iskeyword(s)] [s4] 判断s是否是 python 关键字。在python3中,execprint不再是关键字。
    [s1]: https://pillow.readthedocs.io/en/4.0.x/reference/Image.html#PIL.Image.Image.getpalette
    [s2]: https://docs.python.org/3/library/functions.html#enumerate
    [s3]: https://docs.python.org/3/library/functions.html#zip
    [s4]: https://docs.python.org/3/library/keyword.html#keyword.iskeyword

Python Challenge Wiki

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,308评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,035评论 25 709
  • PYTHON-进阶-ITERTOOLS模块小结转自wklken:http://wklken.me/posts/20...
    C_Y_阅读 4,697评论 0 2
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 11,711评论 0 17
  • 课间,猛然抬头,惊喜地遇见操场一角满树鲜亮的黄色,俏丽而又迷人地贴在树干上。难得一见的阳光,肆无忌惮地温暖着...
    魔头鬼阅读 3,770评论 0 3