Skip to content

sakethakella/Hamming_code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

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

No packages published

Languages