Python Challenge[18]

作者: Recgat | 来源:发表于2017-02-14 11:50 被阅读0次

[Level 18]


Title: can you tell the difference?

除标题之外的提示,源码中注释处有一段信息it is more obvious that what you might think。那么图中左右有什么不同呢?最明显的是左边的亮一点,右边的暗一点。一开始尝试暗的各个单词都不行。换个思路,那么亮呢?light不行,bright可以,搞定。

出来的网页显示ness,百度翻译有海岬,海角的意思,Google翻译是后缀。海角?图片中有海,但是想不出。那么后缀呢?brightness,刚好是bright的名词形式,试下,有了,出来的网页源码中注释maybe consider deltas.gz。替换brightness.html为deltas.gz,下载到该压缩文件。

文件打开看了下,内容像是一堆16进制数字,整体上分为左右两边。是要转为字符串还是图片?字符串太多,应该不是,那么怎么转图片?

整体直接转图片不行,分成两部分转也不行,搜索了下,忘记了标题中tell the difference这茬了。需要使用difflib库。

import difflib
d1, d2 = [], []
with open('delta.txt') as delta:
  for line in delta:
    d1.append(line[:53]+'\n')
    d2.append(line[56:])
compare = difflib.Differ().compare(d1, d2)

打印迭代器中的内容,结果分为三类:以'- ''+ '' '开头的字符串。分别装箱:

with open("f.png","wb") as f,open("f1.png","wb") as f1,open("f2.png","wb") as f2:
  for line in compare:
    bs = bytes([int(i, 16) for i in line[2:].strip().split(" ") if i])
    if line[0] == '+':
      f1.write(bs)
    elif line[0] == '-':
      f2.write(bs)
    else:
      f.write(bs)

得到的三张图片分别显示../hex/bin.htmlbutterfly。那么,[Level 19],butter和fly分别是用户名和密码。

小结

  1. 压缩文件何以这样读取
import gzip
data = gzip.open('deltas.gz')
  1. compare(a, b)比较两个序列的行,并生成增量(行序列)。difflib.Differ类用于比较文本行的序列,并产生人类可读的差异或增量。

Python Challenge Wiki

difflib.ndiff?没尝试。列表解析?可以试着写出来。

More

相关文章

  • Python Challenge[18]

    [Level 18] Title: can you tell the difference? 除标题之外的提示,源...

  • Python挑战:00~03关

    Python Challenge Python Challenge 00 网址: http://www.pytho...

  • Python挑战:04-05关

    Python Challenge Python Challenge 04 现在,我们来挑战第四关,从第三关的结果,...

  • python马丁challenge18.Merging two

    2 Merging two strings into a third oneSay that two string...

  • The Python Challenge(5)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面源码提示: 再点击页面图片显示: 可知是需要...

  • The Python Challenge(8)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 页面和源码中无任何提示,但图片中有一条很明显的灰度线...

  • The Python Challenge(9)

    问题链接 问题链接如下: 答案链接 答案链接如下: 登陆用户名密码为huge和file。 解题思路 阅读源码有如下...

  • The Python Challenge(2)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 将页面给定的字符串根据给定规则进行替换即可,规则如下...

  • The Python Challenge(3)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面提示: 阅读源码,有如下内容: 编写代码从中...

  • The Python Challenge(4)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面提示: 并结合页面源码中的内容,有如下代码:...

网友评论

    本文标题:Python Challenge[18]

    本文链接:https://www.haomeiwen.com/subject/hvgzittx.html