with open('qr_code.txt') as f:
qr_code = f.read().split('\n')
for number in qr_code:
print(f"{int(number):029b}") # Int -> Binary (Zero Pad To Length 29)
11111110010001101111101111111
10000010110110111010001000001
10111010011100100010101011101
10111010110100000110101011101
10111010001011001001101011101
10000010101001110010101000001
11111110101010101010101111111
00000000000011000001100000000
11111011111010111101110101010
11010100110000001000111111001
11100111010110010110100111100
11101001111100110001110011000
00110010010100011000100100110
11001000111011100101111010011
00111111001001111100001011100
11001101111011001000011111001
11111110110010111100100001110
11101100101000001001001111001
10101110000110011100000100000
10010000001100101001110101001
10001010001100001111111110110
00000000101011111000100011011
11111110110001110011101010100
10000010000011011011100011000
10111010110010110100111111100
10111010101000001001100110111
10111010110110010000100111110
10000010100100111000101110010
11111110111100000101001011100
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from PIL import Image
from pyzbar.pyzbar import decode as qr_decode
import os
QRCODE = "qrcode.png" # Output file
with open('qr_code.txt') as f:
numbers = f.read().split('\n')
# Convert binary data to a list of lists representing black (1) and white (0) cells
matrix = []
for number in numbers:
binary = f'{int(number):029b}' # Integer -> Binary (Length=29)
matrix.append( # String Bits -> Integer List
list(
map(
int, list(binary)
)
)
)
# Create a plot for the QR code
plt.matshow(matrix, cmap=ListedColormap(['white', 'black']))
# Remove labels
plt.xticks([])
plt.yticks([])
# Save image
plt.savefig(QRCODE, bbox_inches='tight', pad_inches=0, format='png')
# Display the QR code
plt.show()
image = Image.open(QRCODE)
data = qr_decode(image)[0].data.decode()
print(data)
# Remove file
os.remove(QRCODE)