Skip to content

sakethakella/Hamming_code

Repository files navigation

🔮 Jujutsu Kaisen: Geto's Curse Decoder

Python Version OpenCV NumPy Status

🚨 Spoiler Alert! 🚨

Unveiling the Hidden Plan: Overcoming Geto's Curse


📖 Story Overview

Embark on a daring mission to assist Mechamaru in encoding crucial information about Geto's plan. Meanwhile, Yuji and Megumi must decode the image ensnared by Geto, Jogo, and Mahito holding Gojo in the Prison Realm. Despite the disruptive Gigantic Veil (Tobari) cast by Geto, your mission is to decode the image and thwart Geto's scheme!

🤖 Mechamaru
Encoder
🌪️ Geto's Veil
Channel Noise
⚡ Yuji & Megumi
Decoder Team

🎯 Objective

This project implements a Hamming Error Correction Code system disguised as a Jujutsu Kaisen mission:

  1. Encode an image using Hamming(8,4) error correction
  2. Simulate channel errors (Geto's curse) with random bit flips
  3. Decode and correct errors to recover the original image
  4. Apply XOR decryption to reveal the final hidden message

🛠️ Technical Implementation

Algorithm: Hamming(8,4) Code

Bit Position 0 1 2 3 4 5 6 7
Purpose P1 P2 P3 D1 P4 D2 D3 D4
  • P1, P2, P3, P4: Parity bits for error detection/correction
  • D1, D2, D3, D4: Data bits (4 bits of actual image data)

Error Correction Formula


c1 = D1 ⊕ D2 ⊕ D4
c2 = D1 ⊕ D3 ⊕ D4  
c3 = D2 ⊕ D3 ⊕ D4
c4 = D2 ⊕ D3 ⊕ D4

Error Position = 4×c3 + 2×c2 + 1×c1


📁 Project Structure


jujutsu-kaisen-decoder/
├── 📄 binary_con.py           # Mechamaru's Encoder
├── 📄 Channel.py              # Geto's Veil (Error Simulation)  
├── 📄 decoding.py             # Yuji & Megumi's Decoder
├── 📄 README.md               # This file
├── 🖼️ image.png               # Original input image
├── 🗃️ output.bin              # Encoded data
├── 🗃️ received.bin            # Data after channel errors
├── 🗃️ Array_to_be_Xored.bin   # Geto's curse (XOR mask)
└── 🖼️ outputimage.png         # Final decoded image


🚀 Installation & Setup

Prerequisites


pip install opencv-python numpy

Required Files

  • image.png - Original grayscale image (will be resized to 1000×500)
  • Array_to_be_Xored.bin - XOR mask for final decryption

▶️ Usage Instructions

Step 1: Encode the Image (Mechamaru's Mission)


python binary_con.py

What this does:
  • Loads image.png and converts to grayscale
  • Resizes to 1000×500 pixels (500,000 pixels total)
  • Flattens to binary stream (4,000,000 bits)
  • Applies Hamming(8,4) encoding
  • Saves encoded data to output.bin

Step 2: Simulate Channel Errors (Geto's Veil)


python Channel.py

What this does:
  • Introduces random bit flips with 2% error probability
  • Simulates real-world communication channel noise
  • Saves corrupted data to received.bin

Step 3: Decode & Recover (Yuji & Megumi's Teamwork)


python decoding.py

What this does:
  • Reads corrupted data from received.bin
  • Applies Hamming error correction to each 8-bit codeword
  • Recovers original 4-bit data segments
  • XORs with Array_to_be_Xored.bin to break Geto's final curse
  • Displays and saves the recovered image as outputimage.png

🔧 Code Breakdown

Encoding Process (binary_con.py)


def hamming(input, output):
    # Place data bits
    output[7] = input[3]  # D4
    output[6] = input[2]  # D3  
    output[5] = input[1]  # D2
    output[3] = input[0]  # D1
    
    # Calculate parity bits
    output[0] = input[0] ^ input[1] ^ input[2] ^ input[3]  # P1
    output[1] = input[0] ^ input[1] ^ input[3]             # P2
    output[2] = input[0] ^ input[2] ^ input[3]             # P3
    output[4] = input[2] ^ input[1] ^ input[3]             # P4

Decoding Process (decoding.py)


def hamming_decode(input, output):
    # Check parity bits
    c1 = input[1] ^ input[3] ^ input[5] ^ input[7]
    c2 = input[2] ^ input[3] ^ input[5] ^ input[7]  
    c3 = input[4] ^ input[5] ^ input[6] ^ input[7]
    c4 = input[3] ^ input[5] ^ input[6] ^ input[7]
    
    # Calculate error position
    num = (4*c3) + (2*c2) + (1*c1)
    
    # Correct error if detected
    if num != 0:
        input[num] = input[num] ^ 1
    
    # Extract corrected data
    output[0] = input[3]  # D1
    output[1] = input[5]  # D2
    output[2] = input[6]  # D3
    output[3] = input[7]  # D4


📊 Performance Metrics

Metric Value
Error Correction Capability 1-bit per 8-bit codeword
Code Rate 4/8 = 50%
Channel Error Rate 2% (configurable)
Image Dimensions 1000 × 500 pixels

🧪 Testing & Validation

The system's effectiveness can be measured by:

  1. Visual comparison between original and decoded images
  2. Peak Signal-to-Noise Ratio (PSNR) calculations
  3. Bit Error Rate (BER) before and after correction
  4. Structural Similarity Index (SSIM) for image quality assessment

🐛 Troubleshooting

Common Issues

Image not displaying properly?

  • Ensure OpenCV is properly installed
  • Check that image dimensions are exactly 1000×500 after processing

File not found errors?

  • Make sure all required .bin files are in the project directory
  • Run scripts in the correct order: encoder → channel → decoder

Memory issues?

  • The project processes 4M bits of data - ensure sufficient RAM
  • Consider processing in smaller chunks for very large images

🎨 Customization Options

Adjust Error Rate


# In Channel.py
error_probability = 0.05  # Change from 0.02 to 5% error rate

Change Image Dimensions


# In binary_con.py  
resized_image = cv2.resize(image, (width, height))  # Modify as needed

Different Error Correction Codes

The framework can be extended to support:

  • BCH Codes
  • Reed-Solomon Codes
  • Turbo Codes
  • LDPC Codes

📜 License

This project is released under the MIT License. Feel free to use, modify, and distribute as needed.


🙏 Acknowledgments

  • Gege Akutami - Creator of Jujutsu Kaisen manga
  • Richard Hamming - Inventor of Hamming codes
  • OpenCV Community - Image processing library
  • NumPy Developers - Numerical computing foundation

"The strongest sorcerer in history vs. the strongest error correction code of today!"

Mission Status: ✅ COMPLETE

Geto's curse has been broken, and Gojo's image has been successfully recovered!


Built with ❤️ for the Jujutsu Kaisen and coding communities

About

Application of Hamming-Code to send an image and decode it properly with a mask

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages