给出的附件是一串01代码,内容如下
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
通过观察发现,每一行一共有25个01字符,一共有25行,我们知道,ASCII编码的二进制是8位,Base64编码的二进制是6位,25都无法整除,可以排除。而培根密码则正好是由AB组成的编码,每五位对应一个字符,尝试过后排除。
我们知道矩阵式二维码是由许多小方格组成,每一个方格为有颜色或者无颜色,在代码编制上巧妙地利用构成计算机内部逻辑基础的“0”、“1”比特流的概念。所以我们可以把这些01代码看作一个二维码,我们只需要将这个二维码给还原出来即可。
可以用excel将二维码画出来,因为excel正是一个个的小方格,可以自寻操作,在这里主要记录用Python来编写脚本。
import turtle
def fill(start_x, start_y):
'''
This function will draw a square whose four points are (x, y), (x + 40, y), (x + 40, y + 40), (x, y + 40).
Then the pen go back to the starting coordinates. After that, fill the square up in black.
:param start_x: The x coordinate of the starting point of the pen
:param start_y: The y coordinate of the starting point of the pen
:return: None
'''
turtle.penup() # 将笔抬起,防止移动过程产生轨迹
turtle.goto(start_x, start_y) # 移动到指定点
turtle.pendown() # 落笔
turtle.fillcolor(0, 0, 0) # 填充颜色为黑色
turtle.begin_fill() # 开始填充
# 绘制一个边长为40的正方形
turtle.goto(start_x + 20, start_y)
turtle.goto(start_x + 20, start_y - 20)
turtle.goto(start_x, start_y - 20)
turtle.goto(start_x, start_y)
turtle.end_fill() # 结束填充
turtle.penup()
turtle.screensize(500, 500) # 设置画布为长和宽均为1000像素的正方形
turtle.speed(10) # 将速度设置为最快
turtle.hideturtle() # 将笔隐藏起来
turtle.pencolor(0, 0, 0) # 设置笔的颜色为黑色
x = -250
y = 250
turtle.penup()
turtle.goto(x, y)
with open("0and1.txt","r") as f:
for line in f.readlines():
string = line.strip()
for char in string:
if char == '0':
turtle.penup()
x += 20
turtle.goto(x, y)
else:
fill(x, y)
x += 20
x = -250
y -= 20
turtle.done()
PIL库
这一方法是我看别人的题解时看到的,我做题的时候并不知道PIL库
from PIL import Image
MAX = 25
#二维码大小
pic = Image.new("RGB",(MAX, MAX))
str = """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
"""
# str为获取的01片段
i=0
for y in range (0,MAX):
for x in range (0,MAX):
if(str[i] == '1'):
pic.putpixel([x,y],(0, 0, 0))
else:
pic.putpixel([x,y],(255,255,255))
i = i+1
pic.show()
由于缺少定位符,用CQR将其补全即可