列表

详情


colorful code

红帽杯-2021   MISC   已通过

题目作者: 未知

一  血: ‌‌‌‌‌暂无

一血奖励: 0金币

解  决: 0

提  示:

描  述: colorful code is beautiful, isn't it? flag{}

附  件: 下载

站长题解:

"""
MiaoTony
"""
from PIL import Image


with open('data1', 'r') as fin:
    s = fin.read()

# print(s)
l = s.split(' ')[:-1]
# print(len(l))
# 7067
# 分解质因数 http://tools.jb51.net/jisuanqi/factor_calc
# 37*191

x = 37
y = 191

c = Image.new("RGB", (x, y))

# 原版映射
# colors = ["FFC0C0", "FFFFC0", "C0FFC0",
#           "C0FFFF", "C0C0FF", "FFC0FF",
#           "FF0000", "FFFF00", "00FF00",
#           "00FFFF", "0000FF", "FF00FF",
#           "C00000", "C0C000", "00C000",
#           "00C0C0", "0000C0", "C000C0",
#           "000000", "FFFFFF"]

# 按照 data2 前20个像素来映射
colors = ['000000', '0000C0', '00FFFF', '00FF00', 'FFC0FF', 'FFC0C0', 'C0C0FF', 'C0C000', 'FF00FF', 'FF0000',
          'C00000', 'C000C0', 'FFFFFF', 'FFFF00', 'FFFFC0', '00C000', '00C0C0', 'C0FFFF', 'C0FFC0', '0000FF']


def hex2int(h):
    return (int(h[:2], 16), int(h[2:4], 16), int(h[4:6], 16))


cnt = 0
for i in range(0, x):
    for j in range(0, y):
        color = colors[int(l[cnt])]
        c.putpixel([i, j], hex2int(color))
        cnt += 1

c.show()
c.save("c.png")

# 上传到 https://www.bertnase.de/npiet/npiet-execute.php 执行

去做题