This module provides functionality to convert Python source code files into executable BMP images. The resulting BMP images are compatible with BMP file readers while still containing the original Python source code and be executed in the terminal.
The main goal of this project is to address the challenge of embedding Python source code into a BMP file format. The BMP file specification requires specific signature bytes at the beginning of the file, which conflicts with Python's requirement for specifying the encoding on the first line. This project provides a solution by converting the Python source code into a BMP image while preserving its executable nature.
- Source Code Embedding: Converts Python source code into an image that adheres to BMP file format specifications.
- Executable BMP File: The BMP file generated remains executable and can be interpreted by Python.
- Python 3.10
- NumPy
- Pillow (PIL)
- Colour (colour-science)
- Pygments
- Tqdm
Obs: Later versions of Python (>= 3.11) interpreters can't parse the image generated by this project.
First, clone the repository to your local machine using the following command:
git clone https://github.com/Igorxp5/pyasart
Change into the project directory:
cd pyasart
Install the required Python packages by running:
pip install -r requirements.txt
This will install all the necessary dependencies listed in the requirements.txt
file.
You can now convert a Python source file to a BMP image using the main.py
script:
python -m pyasart.main <input_file> <output_file>
<input_file>
: Path to the Python source file you want to convert.<output_file>
: Path where the resulting BMP image will be saved.
To convert a Python file named fibonacci.py
to an image code_fibonacci.bmp
, run:
python -m pyasart.main fibonacci.py code_fibonacci.bmp
def fibonacci_sequence(n):
sequence = []
a, b = 0, 1
for _ in range(n):
sequence.append(a)
a, b = b, a + b
return sequence
def main():
# Number of Fibonacci numbers to generate
n = 10
# Get the Fibonacci sequence
fib_sequence = fibonacci_sequence(n)
# Iterate over each number in the sequence
for number in fib_sequence:
# Print the current Fibonacci number
print(number)
if __name__ == "__main__":
main()
Note: The above image is not in BMP format. GitHub does not allow to upload BMP files to Markdown files. Hence, downloading the image and trying to run it in Python interpreter won't work.
$ python code_fibonacci.bmp
0
1
1
2
3
5
8
13
21
34
Be cautious when running BMP files through the Python interpreter, especially if you do not know the source of the image. Executing code embedded in a BMP file could potentially be harmful if the source code contains malicious content.
Before running any BMP file through Python, you should inspect the embedded source code. To do this, open the BMP file in a text editor. The Python source code in images generated by this project will be located at the end of the file.
This project is intended for educational and experimental purposes only. The author(s) do not endorse the use of this tool for any illegal or malicious activities. Users are responsible for ensuring that they comply with all applicable laws and regulations when using this software. The author(s) disclaim any liability for misuse or damage resulting from the use of this project. Use at your own risk.
This project is licensed under the MIT License. See the LICENSE
file for more details.