BugKu:1和0的故事

附件:

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} 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值