Skip to content

Instantly share code, notes, and snippets.

@GZTimeWalker
Created April 23, 2023 19:25
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save GZTimeWalker/3ca70a8af2f5830711e9cccc73fb5270 to your computer and use it in GitHub Desktop.
Save GZTimeWalker/3ca70a8af2f5830711e9cccc73fb5270 to your computer and use it in GitHub Desktop.
import qrcode
from qrcode.util import *
def hack_put(self, num, length):
if num == 0:
num = 233 # make a fake length
for i in range(length):
self.put_bit(((num >> (length - i - 1)) & 1) == 1)
qrcode.util.BitBuffer.put = hack_put
qr = qrcode.QRCode(2, qrcode.constants.ERROR_CORRECT_M, mask_pattern=0)
num_data = QRData('1145141', MODE_NUMBER)
data = QRData(b'.', MODE_8BIT_BYTE)
hack_data = QRData(b'', MODE_8BIT_BYTE)
# make sure all data is fit to the max content length for this version
qr.add_data(num_data)
qr.add_data(data)
qr.add_data(num_data)
qr.add_data(data)
qr.add_data(num_data)
qr.add_data(data)
qr.add_data(num_data)
# add a zero length data to make the length of the data to be 233
qr.add_data(hack_data)
qr.make_image()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment