Skip to content

Generates BMP image of your Python source code. The image is still executable by Python interpreter.

License

Notifications You must be signed in to change notification settings

Igorxp5/pyasart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyAsArt

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.

Project Overview

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.

Key Features

  • 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.

Pre-requisites

  • 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.

How to Use

1. Clone the Repository

First, clone the repository to your local machine using the following command:

git clone https://github.com/Igorxp5/pyasart

2. Navigate to the Project Directory

Change into the project directory:

cd pyasart

3. Install Dependencies

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.

4. Generate a BMP Image from Python Source Code

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.

Example

To convert a Python file named fibonacci.py to an image code_fibonacci.bmp, run:

python -m pyasart.main fibonacci.py code_fibonacci.bmp

Source code

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()

Resulting Image

code_fibonacci

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.

Running the image

$ python code_fibonacci.bmp
0
1
1
2
3
5
8
13
21
34

Warning

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.

Disclaimer

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.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

Generates BMP image of your Python source code. The image is still executable by Python interpreter.

Topics

Resources

License

Stars

Watchers

Forks

Languages