发表于 2021-5-11 16:46:23 
| 
查看: 5455
| 
回复: 1
 
 
 
首先题目名称提示:colorful code is beautiful ,这点当时第一时间想到了前段时间安恒赛misc有一题colorful porgramming 
colorful code is beautiful
 
 colorful porgramming 详情见:https://www.bertnase.de/npiet/ data1 是文本文件,data2 是数据文件,用hexdump 查看如下
colorful code is beautiful
 
data1 中是0-19 的数字,用空格分开 。也看不出什么别的(当时在这浪费了比较多的时间)。
colorful code is beautiful
 
data1 暂时也看不出来和图片有什么关系,所以图片的线索在data2 
colorful code is beautiful
 
 十六进制 转换成RGB十进制 ,三个一组from binascii import *
with open('data2','rb') as f:
    f = hexlify(f.read()).decode()
    n = 0
    color_list = []
    for i in range(0,len(f),2):
        i = f[i:i+2]
        color_list.append(int(i,16))
        n += 1
        if n == 3:
            print(tuple(color_list))
            color_list = []
            n = 0
        else:
            continuePS C:\Users\Administrator\Downloads\colorful_code-1> python .\code.py
(0, 0, 0)
(0, 0, 192)
(0, 255, 255)
(0, 255, 0)
(255, 192, 255)
(255, 192, 192)
(192, 192, 255)
(192, 192, 0)
(255, 0, 255)
(255, 0, 0)
(192, 0, 0)
(192, 0, 192)
(255, 255, 255)
(255, 255, 0)
(255, 255, 192)
(0, 192, 0)
(0, 192, 192)
(192, 255, 255)
(192, 255, 192)
(0, 0, 255)
(20, 20, 20)
(21, 21, 21)
(22, 22, 22)
(23, 23, 23)
(24, 24, 24)
(25, 25, 25)
.......
(250, 250, 250)
(251, 251, 251)
(252, 252, 252)
(253, 253, 253)
(254, 254, 254)
(255, 255, 255)data1 中只有0-19 的数字,猜测data1 的0-19 应该是对应data2 种这二十组像素数据的下标。RGB 像素,按照data1 中的顺序,将这些像素putpixel() 即可。data1 中有多少个0-19数字。def str2list():
    with open('data1.txt') as f:
        f = f.read()
        index_list = f.split(' ')
        return index_list
print(str2list())
print(len(str2list()))
colorful code is beautiful
 
data1 最后有两个空格,所以会切多一个元素出来,去掉即可。所以这里总像素是:7067 7067 看起来不像是一个比较常见的图片总像素数,不太好计算,直接在线分解质因数得到宽高http://tools.jb51.net/jisuanqi/factor_calc 
colorful code is beautiful
 
37 ,高为: 191  OK,接下来直接Python简单处理下即可得到flag.png # -*- coding:utf-8 -*-
# Author: mochu7
import PIL
from PIL import Image
from binascii import *
def str2list():
    with open('data1','r') as f:
        f = f.read()
        index_list = f.split(' ')[:-1]
        return index_list
def num2color():
    with open('data2','rb') as f:
        f = hexlify(f.read()).decode()
        n = 0
        idx = 0
        color_dic = {}
        color_list = []
        for i in range(0,len(f),2):
            i = f[i:i+2]
            color_list.append(int(i,16))
            n += 1
            if n == 3:
                color_dic[idx] = tuple(color_list)
                color_list = []
                n = 0
                idx += 1
            elif idx == 20:
                break
    return color_dic
def genimg():
    width, height = 37, 191
    img = Image.new("RGB",(width,height))
    imgpixels = str2list()
    colorlist = num2color()
    pixlist = []
    for pix in imgpixels:
        pixlist.append(colorlist[int(pix)])
    idx = 0
    for w in range(width):
        for h in range(height):
            img.putpixel([w,h], pixlist[idx])
            idx += 1
    img.save('flag.png')
if __name__ == '__main__':
    # print(len(str2list()))
    # print(num2color())
    genimg()
colorful code is beautiful
 
npiet online :https://www.bertnase.de/npiet/npiet-execute.php 
colorful code is beautiful
 
flag  
 
温馨提示:
1.如果您喜欢这篇帖子,请给作者点赞评分,点赞会增加帖子的热度,评分会给作者加学币。(评分不会扣掉您的积分,系统每天都会重置您的评分额度)。
2.回复帖子不仅是对作者的认可,还可以获得学币奖励,请尊重他人的劳动成果,拒绝做伸手党!
3.发广告、灌水回复等违规行为一经发现直接禁言,如果本帖内容涉嫌违规,请点击论坛底部的举报反馈按钮,也可以在【
投诉建议 】板块发帖举报。
总评分: 学币 + 1  
 查看全部评分