编程语言
首页 > 编程语言> > pythonchallenge Level 18

pythonchallenge Level 18

作者:互联网

第18关地址:http://www.pythonchallenge.com/pc/return/balloons.html

账号:huge 密码:file

查看源码

获得提示信息

标题:can you tell the difference?

提示:it is more obvious that what you might think

两只鹅的亮度不一样,亮度brightness

打开http://www.pythonchallenge.com/pc/return/brightness.html

发现还是鹅(⊙o⊙)…

查看源码,得到提示信息maybe consider deltas.gz

打开https://www.pythonchallenge.com/pc/return/deltas.gz 得到下载文件deltas.gz

看样子是要处理deltas.gz

import gzip

file = open("deltas.txt",'wb')
f = gzip.GzipFile("deltas.gz")
data = f.read()
file.write(data)
file.close()

解压deltas.gz,得到一个deltas.txt,打开是两组数字

使用difflib找不同

import gzip, difflib


file = open("deltas.txt",'wb')
f = gzip.GzipFile("deltas.gz")
data = f.read()
file.write(data)
file.close()

file = open("deltas.txt",'r')
dataA = []
dataB = []
for line in file:
    dataA.append(line[:53]+"\n")
    dataB.append(line[56:])

diff = difflib.Differ().compare(dataA,dataB)

left = open("z_18left.png","wb")
right = open("z_18right.png","wb")
diff_data = open("z_18diff.png","wb")
same_data = open("z_18same.png","wb")
for line in diff:
    flag = line[0]
    line_data = line[1:].strip()
    if len(line_data)!=0:
        bs = bytes([int(o,16) for o in line_data.split(" ") if o])
        if flag == '-':
            # print("仅在左边出现",line_data) # - 仅在左边出现
            left.write(bs)
        elif flag == '+':
            # print("仅在右边出现",line_data)  # + 仅在右边出现
            right.write(bs)
        elif flag == '?':
            # print("存在疑问的",line_data) # ? 存在疑问的
            diff_data.write(bs)
        else:
            # print("相同的",line_data) # 相同的
            same_data.write(bs)

left.close()
right.close()
diff_data.close()
same_data.close()

得到四张图,其中

只在左边出现的生成了:fly

只在右边出现的生成了:butter

相同的生成了:../hex/bin.html

获得下一关地址:http://www.pythonchallenge.com/pc/hex/bin.html

账号:butter 密码:fly

标签:open,deltas,pythonchallenge,Level,18,gz,file,line,data
来源: https://www.cnblogs.com/nicole-zhang/p/15557555.html