Skip to content

C# implementation of image encryption and compression using Huffman coding and LFSR techniques for BMP images.

Notifications You must be signed in to change notification settings

Image-Encryption-and-Compression/Huffman-LFSR

Repository files navigation

Huffman-LFSR
Image Encryption and Compression

Securing and Compressing Images with Huffman Coding and Linear Feedback Shift Register (LFSR) Technique.

Huffman-LFSR program

Overview

The Huffman-LFSR Image Encryption and Compression project integrates Huffman coding for efficient image compression with Linear Feedback Shift Register (LFSR) for secure encryption. This tool transforms .bmp images into compressed binary files, including necessary metadata for easy decompression and decryption.

Users can customize encryption parameters for added security, while the project includes benchmarks to assess performance in terms of speed and file size.

Features

  • Huffman Tree Construction: Builds a Huffman tree for each color channel and extracts corresponding Huffman codes based on the constructed tree based on the histogram of this color channel.
  • Image Compression: Compresses .bmp images into a .bin file, which contains metadata about the Huffman trees and the compressed image data.
  • Image Encryption: Provides functionality to encrypt .bmp images using LFSR.
  • Customizable Encryption Parameters: Allows users to input any initial seed and shift position for the encryption process.
  • Image Decryption: Decrypts the image using the same initial seed and shift position used during encryption.
  • Image Decompression: Decompresses images using the saved metadata in the .bin file, restoring them to .bmp format.
  • Complexity Analysis: Offers a detailed complexity analysis using $\LaTeX$

Priority Queue operations Complexity Analysis

Extra Feature: Enhanced Alpha Numeric Key Generation

What is it?

The AlphaLFSR class generates secure alphanumeric keys using a Linear Feedback Shift Register (LFSR) approach. It allows users to input a seed string containing numbers, symbols, and letters, which are then converted into a binary representation for robust encryption. The tapPosition parameter enables customized encryption enhancing randomness in the generated keys.

Advantages

  • Increased Key Space: Alphanumeric keys have a larger key space than binary (only 0,1) keys, making them more resistant to brute-force attacks.
  • User-Friendly: These keys are easier to remember and input by users.
  • Reduced Collision Probability: The diversity of characters minimizes the key collisions, enhancing overall security.
  • Enhanced Security: The combination of a larger key space and alphanumeric diversity boosts security for encryption processes.

Binary File Details

When compressing an image into a .bin file, metadata is saved to facilitate the recovery of the original image during the decompression process. Below is an overview of the file structure and its contents:

File structure:
    seed (int32) tapPosition(byte)
    Red Channel Tree {EOT=2}
    Green Channel Tree {EOT=2}
    Blue Channel Tree
    {EOH=3}
    height width
    image[0,0].red image[0,0].green image[0,0].blue image[0,1].red...
------------------------------------------------------------------------
Tree structure in the file:
    - pre-order traversal
    - 0: internal node, 1: leaf node, 2: end of the tree
    - All bytes
    - End it with 2
------------------------------------------------------------------------
Image structure in the file:
    - Concatenating each 8 bits into one byte

Usage

forward

Forward Operations (Encryption/Compression)

  • Open the desired image to compress/encrypt
  • Provide the initial seed and tap position (default=0)
  • Click on the desired option
  • Results show on left
  • Save bin/image if you want

backward

Backward Operations (Decryption/Decompression)

  • Open binary image/file
  • Provide the initial seed and tap position (default=0)
  • Click on the desired option
  • Results show on left
  • Save bin/image if you want

Benchmarks

The following benchmarks illustrate the performance and efficiency of the image encryption and compression process. Analyzing these benchmarks helps to assess the effectiveness of the implemented algorithms.

Time Benchmark (in seconds)

Level Encryption + Compression Time Decryption + Decompression Time
Small 1 0.040 0.022
Small 2 0.187 0.140
Medium 1 3.015 2.250
Medium 2 6.888 5.491
Large 1 39.361 29.516
Large 2 68.548 54.048

Size Benchmark (in bytes)

Level Bin File Size without Encryption Ratio without Encryption Bin File Size with Encryption Ratio with Encryption
Small 1 60,216 1.223 75,630 0.973
Small 2 189,104 3.967 189,095 3.967
Medium 1 8,044,705 0.187 9,439,488 1.00
Medium 2 15,187,698 0.545 21,504,421 1.157
Large 1 97,047,824 1.364 124,878,942 1.06
Large 2 195,185,524 1.101 195,185,515 1.101

About

C# implementation of image encryption and compression using Huffman coding and LFSR techniques for BMP images.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages