Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Image Encryption Tool 🖼️🔐

A Python-based tool that encrypts and decrypts images using XOR pixel manipulation. Built as part of the Prodigy InfoTech Cybersecurity Internship — Task 02.


What is Image Encryption?

A digital image is made up of pixels. Each pixel has three color values — Red, Green, Blue (RGB) — each ranging from 0 to 255.

Image encryption scrambles these pixel values so the image becomes completely unrecognizable. Decryption reverses the process using the same key to restore the original image perfectly.


How XOR Encryption Works

This tool uses the XOR (exclusive OR) bitwise operation on each pixel channel with a secret key.

Original pixel R = 120
Key = 222

Encrypt: 120 XOR 222 = 166   → saved to encrypted file
Decrypt: 166 XOR 222 = 120   → original pixel restored ✅

XOR is self-reversing with the same key — which is why the same function both encrypts and decrypts. This is the core concept behind stream ciphers used in modern cryptography.


Demo

Encrypted Image Decrypted Image
Completely unrecognizable — colorful noise Pixel-perfect restoration of original

Both images above were produced using XOR key 222 on a 1920x1080 PNG file (2,073,600 pixels processed).


Why it matters in Cybersecurity

  • Demonstrates symmetric encryption — same key encrypts and decrypts
  • Core concept behind stream ciphers like ChaCha20 and RC4
  • Relevant to protecting sensitive images — medical records, surveillance footage
  • Introduces key-based access control — wrong key = wrong output

Features

  • ✅ Encrypt any image file (JPG, PNG, BMP, JPEG)
  • ✅ Decrypt encrypted images back to original using same key
  • ✅ Handles all image formats by converting to RGB automatically
  • ✅ Works on any image size — tested on 1920x1080 (2M+ pixels)
  • ✅ Output file named automatically — no manual naming needed
  • ✅ Input validation — handles wrong paths and unsupported formats

Requirements

pip install Pillow

Installation

# Clone the repository
git clone https://github.com/Abhijithkris0101/PRODIGY_CS_02.git

# Navigate into the folder
cd PRODIGY_CS_02

# Install dependency
pip install Pillow

Usage

python image_encryption.py

Follow the prompts:

  1. Choose 1 to Encrypt or 2 to Decrypt
  2. Enter the full path to your image file
  3. Enter an XOR key (any number between 1 and 255)

The output image is saved automatically in the same folder as your input image.


Sample Terminal Output

=============================================
     IMAGE ENCRYPTION TOOL (XOR Method)
=============================================

What do you want to do?
  1. Encrypt an image
  2. Decrypt an image
Enter choice (1 or 2): 1

Enter full path to your image file: C:\Users\Abhijith P\Pictures\Screenshot (1).png
Enter XOR key (any number between 1 and 255): 222

[*] Processing image: Screenshot (1).png
[*] Image size: 1920 x 1080 pixels
[*] XOR Key: 222
[*] Total pixels to process: 2073600

[+] Done! Output saved as: Screenshot (1)_encrypted.png

[*] Mode     : Encrypted
[*] Key used : 222
[*] Input    : Screenshot (1).png
[*] Output   : Screenshot (1)_encrypted.png

[!] Remember: Use the SAME key to decrypt the encrypted image.
=============================================

Concepts Covered

Concept Description
XOR Operation Bitwise operation that is self-reversing with the same key
Pixel Manipulation Accessing and modifying individual RGB pixel values
Symmetric Encryption Same key encrypts and decrypts — no separate keys needed
Image Processing Using Pillow to read, modify and save images of any format
Stream Cipher Concept Applying a key operation to each unit of data sequentially

How the Core Logic Works

for x in range(width):
    for y in range(height):
        r, g, b = img.getpixel((x, y))  # Get RGB values
        new_r = r ^ key                  # XOR each channel
        new_g = g ^ key
        new_b = b ^ key
        new_img.putpixel((x, y), (new_r, new_g, new_b))

Every pixel is visited. Each RGB channel is XOR'd with the key. The result is written to a new image. Decryption runs the exact same code — XOR reverses itself.


Project Structure

PRODIGY_CS_02/
│
├── image_encryption.py    # Main script
└── README.md              # Documentation

Author

Abhijith P Cyber Security Intern — Prodigy InfoTech

GitHub LinkedIn


⚠️ Disclaimer

This tool is built purely for educational purposes as part of the Prodigy InfoTech Cybersecurity Internship program.

About

A Python tool to encrypt and decrypt text using the Caesar Cipher algorithm | Prodigy InfoTech Cybersecurity Internship — Task 01

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages