2016/12/3-问鼎杯线上赛1-1-Misc

拿到这道题目的文件,是一个压缩包,解压之后,我们看到一个1.txt文件,打开之后全是一堆数字,然后看到255,0,144等内容,估计是图片的像素值。

既然知道是像素值了,在CTF中,一般是8位比特的RGB图片,我们就使用Python写一个脚本来生成这个图片,Python使用的是PIL这个库。将所有的数据分为3个一组

我们可以知道3个一组的长度为95477, 写一个小程序,就可以知道是301*377的图片,然后分别对图片填充像素,就完成了图片的生成。

import os
from PIL import Image

def decode():
    count = 0
    #open the file, and get all the contents
    f = open('./1.txt', 'r')
    data = f.readlines()
    lis = []
    #print(type(data))
    for i in data:
        #将所有的数据以','来分割开
        d = i.split(',')
        s = []
        for j in d:
            s.append(j)
            count += 1
            if count == 3:
                lis.append(s)
                s = []
                count = 0
    #print(len(lis)) 95477 == 301 * 377
    last = []
    for i in lis:
        last.append((int(i[0]), int(i[1]), int(i[2])))

    c = Image.new("RGB",(x,y))
    count = 0
    for i in range (0,301):
        for j in range (0,377):
           c.putpixel([i,j],last[count])
           count += 1
     
    c.show()
    c.save("c.png")

if __name__ == '__main__':
    decode()

好了,这个图片是一个二维码。

文件在这里:http://pan.baidu.com/s/1c1WC50k

原文地址:https://www.cnblogs.com/binlmmhc/p/6130243.html