Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

DES Avalanche Effect Analysis

Experimental analysis of the Avalanche Effect in the Data Encryption Standard (DES) using Python.

This project investigates how a small change in the plaintext or encryption key can produce significant changes in the resulting ciphertext. The experiment focuses on two fundamental cryptographic properties: diffusion and confusion.

Educational Project: This repository is intended for learning and experimental analysis of cryptographic concepts. DES is considered obsolete for modern secure applications and should not be used for new security-sensitive systems.


📌 Overview

The Avalanche Effect is an important property of modern cryptographic algorithms.

A well-designed encryption algorithm should ensure that a small change in the input produces a large and unpredictable change in the output.

In this project, the Avalanche Effect of DES is experimentally analyzed in two scenarios:

  • Diffusion: Changing a single bit of the plaintext while keeping the key unchanged.
  • Confusion: Changing a single bit of the encryption key while keeping the plaintext unchanged.

The resulting ciphertexts are compared at the bit level to measure how many bits change.


🔐 Cryptographic Concepts

Avalanche Effect

The Avalanche Effect describes the phenomenon where changing a small portion of the input to a cryptographic algorithm results in a significant change in its output.

For a strong block cipher, changing a single bit should ideally affect approximately half of the ciphertext bits.

This property makes it difficult to establish a direct relationship between the input and encrypted output.

Diffusion

Diffusion refers to the spreading of the influence of plaintext bits throughout the ciphertext.

In this experiment:

Plaintext
   ↓
Change one bit
   ↓
DES Encryption
   ↓
Compare ciphertexts
   ↓
Measure changed bits

Confusion

Confusion refers to making the relationship between the encryption key and ciphertext as complex as possible.

In this experiment:

Key
 ↓
Change one bit
 ↓
DES Encryption
 ↓
Compare ciphertexts
 ↓
Measure changed bits

🧪 Experiment Design

The experiment uses DES encryption and compares pairs of ciphertexts generated from slightly different inputs.

Experiment 1 — Diffusion

The plaintext is modified by changing a single bit while keeping the encryption key unchanged.

The two ciphertexts are then compared to determine the percentage of changed bits.

Experiment 2 — Confusion

The encryption key is modified by changing a single bit while keeping the plaintext unchanged.

The resulting ciphertexts are compared to measure the effect of the key modification.


📊 Results

The experiments demonstrate the Avalanche Effect of DES.

The measured results in the original experiment were approximately:

Property Changed Bits
Diffusion ~53%
Confusion ~46%

These values show that changing only one bit in the plaintext or encryption key can affect a large portion of the resulting ciphertext.

The results are close to the ideal behavior of approximately 50% changed bits, which is generally expected from a strong avalanche property.

Results may vary depending on the input values and experimental configuration.


📈 Visualization

The project includes a visualization of the experimental results:

DES Avalanche Effect Analysis

The visualization helps illustrate the difference between the diffusion and confusion experiments.


🛠️ Technologies

  • Python
  • PyCryptodome
  • DES
  • ECB Mode
  • Bit-level comparison
  • Data visualization

📂 Project Structure

Cryptography/
│
├── DES_analysis/
│   └── DES_analysis.py
│
├── des_avalanche_analysis.png
│
├── .gitignore
└── README.md

⚙️ Installation

1. Clone the repository

git clone https://github.com/AliValizade/Cryptography.git
cd Cryptography

2. Install dependencies

Install the required cryptographic library:

pip install pycryptodome

Alternatively, if you use a virtual environment:

python -m venv .venv

Activate it on Windows:

.venv\Scripts\activate

Or on Linux/macOS:

source .venv/bin/activate

Then install the dependency:

pip install pycryptodome

▶️ Running the Experiment

From the repository root:

python DES_analysis/DES_analysis.py

The script performs the DES encryption experiments and calculates the percentage of changed ciphertext bits.


🔎 How the Analysis Works

The general procedure is:

  1. Define the original plaintext.
  2. Define the original DES encryption key.
  3. Encrypt the original plaintext.
  4. Modify one bit of the plaintext.
  5. Encrypt the modified plaintext using the same key.
  6. Compare the resulting ciphertexts to measure diffusion.
  7. Modify one bit of the encryption key.
  8. Encrypt the original plaintext using the modified key.
  9. Compare the resulting ciphertexts to measure confusion.
  10. Calculate the percentage of changed bits.
  11. Visualize the experimental results.

🧮 Measuring the Avalanche Effect

The ciphertexts are compared bit by bit.

The percentage of changed bits can be calculated as:

Changed Bits Percentage =
(Number of Changed Bits / Total Number of Bits) × 100

For an ideal avalanche effect, changing one input bit should result in approximately half of the output bits changing.


🔬 Technical Notes

This project uses:

  • DES as the block cipher
  • ECB (Electronic Codebook) mode
  • 64-bit DES blocks
  • Bit-level ciphertext comparison

The purpose of using ECB in this project is experimental analysis of DES behavior rather than secure message encryption.


⚠️ Limitations

This project is an educational cryptography experiment and has several limitations:

  • DES is an obsolete encryption standard.
  • ECB mode is not recommended for encrypting real-world data.
  • The experiment is based on a limited number of test cases.
  • Avalanche measurements can vary depending on the selected plaintext and key.
  • The measured percentage should not be interpreted as a complete evaluation of the security of DES.

For modern applications, algorithms such as AES should be considered instead of DES.


🎯 Learning Objectives

This project was developed to explore and better understand:

  • Cryptographic diffusion
  • Cryptographic confusion
  • Avalanche Effect
  • Block cipher behavior
  • DES encryption
  • Bit-level comparison
  • Experimental cryptography
  • Python-based cryptographic programming

🚀 Possible Improvements

Potential future improvements include:

  • Running the experiment over a large number of random plaintexts and keys.
  • Performing statistical analysis of the results.
  • Comparing DES with AES.
  • Generating distributions of changed-bit percentages.
  • Adding automated tests.
  • Improving result visualization.
  • Comparing different block cipher modes.
  • Providing reproducible experiment configurations.

👨‍💻 Author

Ali Valizadeh

Python Developer · Django · AI, NLP & Automation · University Instructor

GitHub: https://github.com/AliValizade


📄 License

This project is provided for educational and research purposes.

No explicit open-source license has been specified for this repository.

About

DES Avalanche Effect Analysis — Experimental analysis of diffusion and confusion in the DES encryption algorithm using Python.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages