Skip to content

tobiia/differential_cryptanalysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Differential Cryptanalysis (Learning Project)

An implementation of a simplified differential cryptanalysis attack on a toy block cipher. The project was undertaken as I was teaching myself some fundamentals of cryptography. I followed along with the ideas presented in this explanation, then implemented it in python to better understand the process.

Cipher Structure

The target cipher is intentionally minimal so that its structure can be analyzed directly:

  • 16-bit block size with 4 rounds
  • A fixed S-box (4-bit substitution)
  • A simple permutation table
  • Round keys XORed with the state at each step

Approach

The code carries out the main steps of a differential attack:

  1. Generate a Difference Distribution Table (DDT) The DDT records how input XOR differences propagate through the S-box, showing which output differences are more probable.

  2. Identify Differential Trails By combining the most probable transitions, we can construct differential trails through the cipher.
    Example trails observed include:

    • 0x000b -> 0x1400 with probability ≈ 0.0527
    • 0x0600 -> 0x00A8 with probability ≈ 0.0352
  3. Apply Chosen-Plaintext Pairs Using pairs of plaintexts with fixed input differences, the ciphertexts are partially decrypted under candidate subkeys. Key guesses are ranked by how frequently they lead to the expected XOR output along a given trail.

  4. Recover Round Key Information Trails with only one or two active S-boxes in the final round reduce the key search space, making it possible to identify the most likely round key bits.

Running the Code

python diff_crypt.py

The program will:

  • Print the generated S-box and permutation table
  • Compute the DDT
  • Show the most probable differential trails
  • Test candidate subkeys using chosen-plaintext pairs
  • Output the most likely round key

Results

  • Successfully recovered the 5th round key using two trails:
    • First trail probability ≈ 5.3%
    • Second trail probability ≈ 3.5%
  • Combined, these led to a confident guess of the correct round key bits.

See the pdf for more details.

About

A simplified differential cryptanalysis attack on a toy block cipher for learning & exploration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages