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.
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.
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 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 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
The experiment uses DES encryption and compares pairs of ciphertexts generated from slightly different inputs.
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.
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.
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.
The project includes a visualization of the experimental results:
The visualization helps illustrate the difference between the diffusion and confusion experiments.
- Python
- PyCryptodome
- DES
- ECB Mode
- Bit-level comparison
- Data visualization
Cryptography/
│
├── DES_analysis/
│ └── DES_analysis.py
│
├── des_avalanche_analysis.png
│
├── .gitignore
└── README.md
git clone https://github.com/AliValizade/Cryptography.git
cd CryptographyInstall the required cryptographic library:
pip install pycryptodomeAlternatively, if you use a virtual environment:
python -m venv .venvActivate it on Windows:
.venv\Scripts\activateOr on Linux/macOS:
source .venv/bin/activateThen install the dependency:
pip install pycryptodomeFrom the repository root:
python DES_analysis/DES_analysis.pyThe script performs the DES encryption experiments and calculates the percentage of changed ciphertext bits.
The general procedure is:
- Define the original plaintext.
- Define the original DES encryption key.
- Encrypt the original plaintext.
- Modify one bit of the plaintext.
- Encrypt the modified plaintext using the same key.
- Compare the resulting ciphertexts to measure diffusion.
- Modify one bit of the encryption key.
- Encrypt the original plaintext using the modified key.
- Compare the resulting ciphertexts to measure confusion.
- Calculate the percentage of changed bits.
- Visualize the experimental results.
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.
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.
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.
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
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.
Ali Valizadeh
Python Developer · Django · AI, NLP & Automation · University Instructor
GitHub: https://github.com/AliValizade
This project is provided for educational and research purposes.
No explicit open-source license has been specified for this repository.
