diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..bf6858e --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 tcsenpai + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/dist/qrare-1.0.0-py3-none-any.whl b/dist/qrare-1.0.0-py3-none-any.whl new file mode 100644 index 0000000..0a3ef74 Binary files /dev/null and b/dist/qrare-1.0.0-py3-none-any.whl differ diff --git a/dist/qrare-1.0.0.tar.gz b/dist/qrare-1.0.0.tar.gz new file mode 100644 index 0000000..ad450b4 Binary files /dev/null and b/dist/qrare-1.0.0.tar.gz differ diff --git a/example_with_files.py b/example_with_files.py deleted file mode 100644 index 9093129..0000000 --- a/example_with_files.py +++ /dev/null @@ -1,11 +0,0 @@ -import qraro - -with open("pika.webp", "rb") as f: - data = f.read() - -qraro.bin_to_qr(data, chunk_size=1000, box_size=10, border=4) - -test_file = qraro.qr_to_bin() - -with open("pika_out.webp", "wb") as f: - f.write(test_file) \ No newline at end of file diff --git a/example_with_string.py b/example_with_string.py deleted file mode 100644 index 31fc5f7..0000000 --- a/example_with_string.py +++ /dev/null @@ -1,9 +0,0 @@ -import qraro - -# Example usage -original_data = b"This is a binary string \x00\x01\x02 with some non-printable characters." -qraro.bin_to_qr(original_data, chunk_size=50) - -decoded_data = qraro.qr_to_bin() -print("Decoded data:", decoded_data) -print("Original and decoded data match:", original_data == decoded_data) \ No newline at end of file diff --git a/input_test_file.txt b/input_test_file.txt deleted file mode 100644 index 9b7c9c9..0000000 --- a/input_test_file.txt +++ /dev/null @@ -1,5 +0,0 @@ -This file can be used (and is used) as an example input file for the `example_with_files.py` script. - -Feel free to modify it as needed. - -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut purus eget sapien. \ No newline at end of file diff --git a/pika.webp b/pika.webp deleted file mode 100644 index ba82749..0000000 Binary files a/pika.webp and /dev/null differ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d3c801b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[build-system] +requires = ["setuptools>=61.0", "qrcode", "qrtools", "compress", "zxing", "pillow"] +build-backend = "setuptools.build_meta" +[project] +name = "qrare" +version = "1.0.0" +authors = [ + { name="tcsenpai", email="dev@tcsenpai.com" }, +] +description = "Compresses data into QR codes and decompresses them back into the original data." +readme = "README.md" +requires-python = ">=3.8" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +[project.urls] +Homepage = "https://github.com/tcsenpai/qrare" +Issues = "https://github.com/tcsenpai/qrare/issues" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e2b2768..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -qrcode -Pillow -zxing -qrtools -compress \ No newline at end of file diff --git a/src/qrare.egg-info/PKG-INFO b/src/qrare.egg-info/PKG-INFO new file mode 100644 index 0000000..4a5f698 --- /dev/null +++ b/src/qrare.egg-info/PKG-INFO @@ -0,0 +1,116 @@ +Metadata-Version: 2.1 +Name: qrare +Version: 1.0.0 +Summary: Compresses data into QR codes and decompresses them back into the original data. +Author-email: tcsenpai +Project-URL: Homepage, https://github.com/tcsenpai/qrare +Project-URL: Issues, https://github.com/tcsenpai/qrare/issues +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Requires-Python: >=3.8 +Description-Content-Type: text/markdown +License-File: LICENSE.md + +# 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. + +## Dependencies + +- Python 3.x +- qrcode +- qrtools +- compress +- Pillow (PIL) +- zxing + +Install the required libraries using pip: + +`pip install qrcode pillow zxing qrtools compress` + +Or install the dependencies using: + +`pip install -r requirements.txt` + +## Functions + +### bin_to_qr(data, chunk_size=100, filename_prefix="qr_code") + +Encodes binary data into a series of QR code images. + +Parameters: +- `data` (bytes): The binary data to encode. +- `chunk_size` (int, optional): The maximum number of hexadecimal characters per QR code. Default is 100. +- `filename_prefix` (str, optional): The prefix for the generated QR code image filenames. Default is "qr_code". + +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: +- `filename_prefix` (str, optional): The prefix of the QR code image filenames to decode. Default is "qr_code". + +Returns: +- `bytes`: The decoded binary data, or `None` if no QR codes were found. + +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 + +```python + +# Encode binary data into QR codes +import qraro + +original_data = b"This is a binary string \x00\x01\x02 with some non-printable characters. +qraro.bin_to_qr(original_data, chunk_size=50) + +# Decode QR codes back into binary data +import qraro + +decoded_data = qraro.qr_to_bin() +print("Decoded data:", decoded_data) +print("Original and decoded data match:", original_data == decoded_data) + +``` + +## Notes + +- The script automatically determines the appropriate QR code version based on the data size. +- Data is compressed using gzip before being encoded into QR codes to maximize data capacity. +- Data is then decompressed using gzip after being decoded from QR codes. +- Error correction level is set to LOW (L) to maximize data capacity. +- The script handles binary data, including non-printable characters. +- THe script has a fallback method that (until now) allows for a 100% error free decoding. +- QR code images are saved and read from the current working directory. +- Ensure you have write permissions in the directory where the script is run. + +## Error Handling + +- The script includes basic error handling for file not found and decoding errors. +- If an error occurs during decoding, it will be printed to the console. + +## Limitations + +- The maximum data capacity depends on the QR code version and error correction level. +- Very large binary files may require a large number of QR codes. +- The script assumes that QR codes will be scanned in the correct order for decoding. diff --git a/src/qrare.egg-info/SOURCES.txt b/src/qrare.egg-info/SOURCES.txt new file mode 100644 index 0000000..f597fc0 --- /dev/null +++ b/src/qrare.egg-info/SOURCES.txt @@ -0,0 +1,9 @@ +LICENSE.md +README.md +pyproject.toml +src/qrare.egg-info/PKG-INFO +src/qrare.egg-info/SOURCES.txt +src/qrare.egg-info/dependency_links.txt +src/qrare.egg-info/top_level.txt +src/qraro_tcsenpai/__init__.py +src/qraro_tcsenpai/qrare.py \ No newline at end of file diff --git a/src/qrare.egg-info/dependency_links.txt b/src/qrare.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/qrare.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/src/qrare.egg-info/top_level.txt b/src/qrare.egg-info/top_level.txt new file mode 100644 index 0000000..652fef8 --- /dev/null +++ b/src/qrare.egg-info/top_level.txt @@ -0,0 +1 @@ +qraro_tcsenpai diff --git a/src/qraro_tcsenpai/__init__.py b/src/qraro_tcsenpai/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/qraro.py b/src/qraro_tcsenpai/qrare.py similarity index 100% rename from qraro.py rename to src/qraro_tcsenpai/qrare.py