├── README.md ├── decrypted_image.jpg ├── encrypted_image.jpg ├── input.jpg └── task-02.py /README.md: -------------------------------------------------------------------------------- 1 | **Title** 2 | 3 | *Simple Image Pixel Manipulation* 4 | 5 | **Description** 6 | 7 | This Python program demonstrates basic image manipulation techniques using the Pillow library. It allows you to perform a simple encryption and decryption process on images by swapping red and blue pixel channels. 8 | 9 | **How to Use** 10 | 11 | 1. **Prerequisites:** 12 | - Install the Pillow library: `pip install Pillow` 13 | 14 | 2. **Save the code:** 15 | - Save the provided code as a Python file (e.g., `pixel_manipulation.py`). 16 | 17 | 3. **Run the script:** 18 | - Open your terminal and navigate to the directory where you saved the script. 19 | - Execute the script using the following command: 20 | 21 | ```bash 22 | python pixel_manipulation.py 23 | ``` 24 | 25 | **Note:** This script uses hardcoded file paths for demonstration purposes. You'll need to modify these paths to point to your desired input and output images. Here's an example with placeholders: 26 | 27 | ```bash 28 | python pixel_manipulation.py "path/to/your/input_image.jpg" "path/to/encrypted_image.jpg" "path/to/decrypted_image.jpg" 29 | ``` 30 | 31 | **Understanding the Code** 32 | 33 | - The script utilizes the Pillow library to load, manipulate, and save images. 34 | - The `encrypt_image` function opens the input image, iterates through each pixel, swaps the red and blue channel values, and saves the modified image as the encrypted version. 35 | - The `decrypt_image` function performs the reverse operation, swapping the channels back to their original positions, effectively decrypting the image. 36 | 37 | **Disclaimer** 38 | 39 | This code is intended for educational purposes only. It highlights a basic pixel manipulation technique but does not provide robust security for image encryption. 40 | 41 | **License** 42 | 43 | This project is licensed under the MIT License. 44 | 45 | **Feel free to use this code for learning and experimentation!** 46 | -------------------------------------------------------------------------------- /decrypted_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OracleBrain/Pixel-Manipulation-for-Image-Encryption/d313790b645e67b054164c09b526b9e90f3072b3/decrypted_image.jpg -------------------------------------------------------------------------------- /encrypted_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OracleBrain/Pixel-Manipulation-for-Image-Encryption/d313790b645e67b054164c09b526b9e90f3072b3/encrypted_image.jpg -------------------------------------------------------------------------------- /input.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OracleBrain/Pixel-Manipulation-for-Image-Encryption/d313790b645e67b054164c09b526b9e90f3072b3/input.jpg -------------------------------------------------------------------------------- /task-02.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | 3 | def encrypt_image(input_path, output_path, key): 4 | img = Image.open(input_path) 5 | pixels = img.load() 6 | 7 | width, height = img.size 8 | 9 | for i in range(width): 10 | for j in range(height): 11 | r, g, b = pixels[i, j] 12 | 13 | # swapping red and blue channels 14 | encrypted_pixel = (b, g, r) 15 | 16 | pixels[i, j] = encrypted_pixel 17 | 18 | img.save(output_path) 19 | print("Image encrypted successfully!") 20 | 21 | def decrypt_image(input_path, output_path, key): 22 | img = Image.open(input_path) 23 | pixels = img.load() 24 | 25 | width, height = img.size 26 | 27 | for i in range(width): 28 | for j in range(height): 29 | r, g, b = pixels[i, j] 30 | 31 | # swapping red and blue channels back 32 | decrypted_pixel = (b, g, r) 33 | 34 | pixels[i, j] = decrypted_pixel 35 | 36 | img.save(output_path) 37 | print("Image decrypted successfully!") 38 | 39 | # image path 40 | input_image = r"C:\Users\aashis\Desktop\Internship-01\Task-02\input.jpg" 41 | encrypted_image = r"C:\Users\aashis\Desktop\Internship-01\Task-02\decrypted_image.jpg" 42 | decrypted_image = r"C:\Users\aashis\Desktop\Internship-01\Task-02\encrypted_image.jpg" 43 | 44 | 45 | # Encrypt the image 46 | encrypt_image(input_image, encrypted_image, key=None) 47 | 48 | # Decrypt the image 49 | decrypt_image(encrypted_image, decrypted_image, key=None) 50 | --------------------------------------------------------------------------------