tcsenpai / qrare

33 stars 1 forks source link

QRare

Store files into QR Codes and decode them later!

Now with gzip compression and fallback to qrtools!

This Python module provides functionality to encode arbitrary binary data into a series of QR codes and decode them back into the original data. It uses the qrcode library for encoding and the zxing and qrtools libraries for decoding.

Installation

Using pip

Pubished at https://pypi.org/project/qrare/

pip install qrare

From this repository

git clone https://github.com/tcsenpai/qrare/

cd qrare

Install dependencies

Install the required libraries using pip:

pip install qrcode pillow zxing qrtools compress

Or install the dependencies using:

pip install -r requirements.txt

Functions & Usage

bin_to_qr(data, chunk_size=100, filename_prefix="qr_code")

Encodes binary data into a series of QR code images.

Parameters:

This function performs the following steps:

  1. Compresses the binary data using gzip.
  2. Converts the binary data to a hexadecimal string.
  3. Splits the hex string into chunks of the specified size.
  4. Creates a QR code for each chunk, including chunk number and total chunk count.
  5. Saves each QR code as a PNG image.

qr_to_bin(filename_prefix="qr_code")

Decodes a series of QR code images back into the original binary data.

Parameters:

Returns:

This function performs the following steps:

  1. Iterates through numbered QR code images with the given prefix.
  2. Decodes each QR code using the zxing library, falling back to qrtools if zxing cannot decode a qrcode.
  3. Extracts chunk information and data from each decoded QR code.
  4. Reconstructs the original hexadecimal string from the chunks.
  5. Converts the hexadecimal string back to binary data.
  6. Decompresses the binary data using gzip.
  7. Returns the decompressed binary data.

Usage Example


# Encode binary data into QR codes
import qrare

original_data = b"This is a binary string \x00\x01\x02 with some non-printable characters.
qrare.bin_to_qr(original_data, chunk_size=50)

And vice versa

# Decode QR codes back into binary data
import qrare

decoded_data = qrare.qr_to_bin()
print("Decoded data:", decoded_data)
print("Original and decoded data match:", original_data == decoded_data)

Notes

Error Handling

Limitations