Scratch ERCode Writeup
原创2024年11月12日...大约 2 分钟
题目描述
I made a ERCode generator! Featuring red-blue encoding, looks more colorful than QRCode, right?
Flag is in the ERCodes.
Scratch: https://scratch.mit.edu/projects/1086251314/
Chilli Level:
观察 Scratch 源码,从用户输入的文本通过一堆算法,用点阵的方式生成了一个 ERCodes,然后通过一个 pen
画出来,所以我们只需要把附件中的 500 张图片数据通过逆向算法解码就可以得到用户输入的内容
对 1.png
做了下测试,数据是二进制,每个像素代表一位,从内圈到外圈,从菱形的底端开始读取,左边读一个右边读一个
那么我们以此类推,一次性用顺时针把二进制数据读取出来,再反向把后面的数据插入回去,就可以读到数据
from PIL import Image
def get_pixel_hex_color(image_path, x, y):
# #0000ff 蓝色, #ff0000 红色
with Image.open(image_path) as img:
r, g, b = img.getpixel((x, y))
color = "#{:02x}{:02x}{:02x}".format(r, g, b)
return "0" if color == "#0000ff" else "1" if color == "#ff0000" else "?"
for img in range(1,501):
r = 25
text_bin = ""
for _ in range(7):
bin = ""
x = 240 + 1
y = 203 + 1 + _
for i in range(r):
x -= 1
y -= 1
bin += get_pixel_hex_color(f"images/{img}.png", x, y)
for i in range(r-1):
x += 1
y -= 1
bin += get_pixel_hex_color(f"images/{img}.png", x, y)
for i in range(r-1):
x += 1
y += 1
bin += get_pixel_hex_color(f"images/{img}.png", x, y)
for i in range(r-2):
x -= 1
y += 1
bin += get_pixel_hex_color(f"images/{img}.png", x, y)
r += 1
for i in range(len(bin)//2+1):
text_bin += bin[i]
if i != 0 and i != len(bin)//2:
text_bin += bin[len(bin)-i]
text = ""
for i in range(0, len(text_bin), 8):
text += chr(int(text_bin[i:i+8], 2))
print(f"{text}", end="")
运行代码后使用搜索找到 flag
Powered by Waline v3.3.1