018. can you tell the difference?

关卡地址#

解决方案:#

思路:#

可以很明显的看出图片左右两部分的亮度不同,但还是看一下源代码的提示:

it is more obvious that what you might think

替换url为bright会提示:

ness

访问brightness仍然是相同的图片,再次查看源代码的提示:

maybe consider deltas.gz

下载解压后发现一个delta.txt文件,打开后前4行数据如下:

89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00   89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00
02 8a 00 00 00 c8 08 02 00 00 00 e0 19 57 95 00 00 00   02 8a 00 00 00 c8 08 02 00 00 00 e0 19 57 95 00 00 00
09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 00 9a 9c 18   09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 00 9a 9c 18
00 00 00 07 74 49 4d 45 07 d5 05 07 0c 18 32 98 c6 a0   00 00 00 07 74 49 4d 45 07 d5 05 07 0c 18 32 98 c6 a0

可以看出这是两个文件合并在一起的,结合标题,需要比较两者不同。

比较结果有三种:

"  b'89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00'",
"- b'89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00'",
"+ b'89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00'",
  1. ’ ’ 表示两个序列都有
  2. ‘-’ 表示只有第一个序列有
  3. ‘+’ 表示只有第二个序列有

将这三种结果分别输出到三个文件,文件格式是png

输出文件时需要将十六进制字符串转换为二进制byte。

最后得到图片内容分别是:

  1. ../hex/bin.html
  2. fly
  3. butter

1是下一关地址,访问需要认证。经过测试:

2是密码,3是用户名

代码:#

import helper
path="../../Data/018"
helper.ensureDir(path)

# ================================
# 使用http认证,下载文件
import urllib.request
helper.installHTTPBasicAuthOpener("huge", "file")

gif="http://www.pythonchallenge.com/pc/return/deltas.gz"
(filename, headers)=urllib.request.urlretrieve(gif, path+"/deltas.gz")
# ================================

import gzip
with gzip.open(filename) as gz:
    lines=gz.readlines()
    
file1=[str(line)[2:55] for line in lines]
file2=[str(line)[58:111] for line in lines]

import difflib
d=difflib.Differ()
rst=list(d.compare(file1, file2))

# 查看比较结果
# tmp=path+"/compare.txt"
# fp=open(tmp, 'w')
# fp.write(''.join(rst))
# fp.close()
# from pprint import pprint
# pprint(rst)

pngs=[''.join(filter(lambda l: l[0]==c, rst)) for c in ' -+']

import binascii
for i in range(len(pngs)):
    png=pngs[i].replace(' ','').replace('/n','').replace('\'','').replace('+','').replace('-','')
    # print(png)
    open('%s/delta%d.png' % (path,i), 'wb').write(binascii.unhexlify(png))

print("please see the folder: ", path)
package main

import(
	"fmt"
)

func (c *Challenge) Challenge018() {
	
	fmt.Println("result: ")
}

最终结果: ../hex/bin.html#

下一关地址#

❤️ 如果这篇文章对你有帮助,欢迎赞助支持我继续维护 ❤️

☕ Support me ⚡ 爱发电赞助