附件:
0000000001110010000000000
0000000000011110100000000
0000000001110001000000000
0000000010111100000000000
0000000010101010000000000
0000000001100010100000000
0000000010101010100000000
0000000001000001100000000
1100011101110110100011000
0001000010110010010010100
0100111101000011101110011
0011110100101011001001001
1000001001100001001101000
1111000111111011100101000
1011011111001101111110111
1000110110010010101101100
1000111100111111111110111
0000000010110001100010100
0000000010010100101010001
0000000010101010100011001
0000000000100111111110010
0000000000011001011110111
0000000001001100100100001
0000000011000011011011001
0000000011010000101110101
题目附件是一个txt,内容是一个25*25的01矩阵。用1表示黑色方块,0表示白色方块,猜测这是一个缺少定位符的二维码。
为了方便操作,先去掉换行符:
with open('1和0的故事.txt', 'r') as f1:
with open('1.txt', 'w') as f2:
for line in f1.readlines():
f2.write(line.strip())
方法一(Excel)
import xlwt
# 创建一个xls
book = xlwt.Workbook()
# 创建一个样式 (黑色填充,无边界)
Style = xlwt.easyxf('pattern: pattern solid, fore_colour black; font: height 250')
# 添加一个表单,允许覆盖
table = book.add_sheet('flag_code', cell_overwrite_ok=True)
with open('1.txt', 'r') as f:
s = f.read()
MAX = 25 # 二维码边长,若大于256需要用xlsxwriter模块
i = 0
for y in range(0, MAX):
for x in range(0, MAX):
table.col(x).width = 256*3 # 256为衡量单位,3表示3个字符宽度
if(s[i] == '1'): # 如果是1则在Excel上涂黑
table.write(y, x, '', style=Style)
i += 1
book.save('1和0的故事.xls')
# 7*7的二维码定位符
locator = [
[1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1]
]
def draw_locator(y, x):
for i in range(7):
for j in range(7):
pos1 = locator[i][j]
if pos1 == 1: # 如果是1则在Excel上涂黑
table.write(y+i, x+j, '', style=Style)
draw_locator(0, 0) # 左上角
draw_locator(0, 18) # 右上角
draw_locator(18, 0) # 左下角
book.save('1和0的故事.xls')
方法二(PIL)
from PIL import Image
with open('1.txt', 'r') as f:
s = f.read()
MAX = 25 # 二维码边长
pic = Image.new("RGB", (MAX, MAX))
i = 0
for y in range(0, MAX):
for x in range(0, MAX):
if(s[i] == '1'):
pic.putpixel([x, y], (0, 0, 0))
else:
pic.putpixel([x, y], (255, 255, 255))
i += 1
pic.show()
pic.save("1和0的故事.png")
# 7*7的二维码定位符
locator = [
[1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1]
]
def draw_locator(y, x):
for i in range(7):
for j in range(7):
pos1 = locator[i][j]
if(pos1 == 1):
pic.putpixel([x+i, y+j], (0, 0, 0))
else:
pic.putpixel([x+i, y+j], (255, 255, 255))
draw_locator(0, 0) # 左上角
draw_locator(0, 18) # 右上角
draw_locator(18, 0) # 左下角
pic.show()
pic.save("1和0的故事.png")
flag{QR_c0de_1s_1nterest1n9}