Skip to main content

Automated cryptanalysis library for substitution permutation network

Project description

Auto Cryptanalysis

This project implements python module for automatic cryptanalysis of Substitution Permutation Network ciphers by performing extensive linear and differential characteristic search and finding keybits

Structure

The project is structured as follows:

  • The cryptanalysis directory contains the main Python module for cryptanalysis.
  • The tests directory contains unit tests for the module
  • The examples directory contains examples for using the module
  • The docs directory contains html documentation autogenerated from code doc-strings

Installation

Pip

The project can be installed directly from pip

pip install cryptanalysis

Otherwise clone and install is also viable

git clone https://github.com/deut-erium/auto-cryptanalysis.git
cd auto-cryptanalysis
pip install .

Requirements

This project requires Python3.6+ and the following Python packages:

  • z3-solver
  • tqdm

Requirements are auto installed as a part of the installation process but

You can also install these packages using pip:

pip install -r requirements.txt

Usage

import random
import cryptanalysis

sbox_size = 6 # bits
pbox_size = sbox_size * 16 # 16 sboxes
num_rounds = 4
sbox = list(range(2**sbox_size))
pbox = list(range(pbox_size))
# random pbox and sbox
random.shuffle(sbox)
random.shuffle(pbox)

random_key = random.randint(0, (2**pbox_size) - 1)
# random spn instance whose key is unknown to us
spn = cryptanalysis.SPN(sbox, pbox, random_key, num_rounds)

d_c = cryptanalysis.differential_cryptanalysis.DifferentialCryptanalysis(sbox, pbox, num_rounds+1)
# override batch_encrypt with the oracle

max_num_encryptions = 50000
def batch_encrypt(plaintexts):
    return [spn.encrypt(i) for i in plaintexts]

d_c.batch_encrypt = batch_encrypt
differential_characteristics = d_c.characteristic_searcher.search_exclusive_masks()
last_round_key_blocks = d_c.find_last_roundkey(differential_characteristics, max_num_encryptions//16)

print("recovered last round key:",last_round_key_blocks)
print("original last round key:",d_c.int_to_list(spn.round_keys[-1]))

Tests

You can run the tests using the following command:

python -m unittest discover

Documentation

Read the documentation
Autogenerated documentation from code doc-strings can be found under docs

Contributing

Please feel free to submit pull requests or create issues if you find any bugs or have any suggestions for improvements.
List of ideas to implement/TODO is present in CONTRIBUTING.md

License

This project is licensed under the GPL License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cryptanalysis-0.0.2.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

cryptanalysis-0.0.2-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file cryptanalysis-0.0.2.tar.gz.

File metadata

  • Download URL: cryptanalysis-0.0.2.tar.gz
  • Upload date:
  • Size: 30.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for cryptanalysis-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6136fa272330162d77882a5120cb5322092de5516e569b6cba49aa6b1c00760d
MD5 3102eaa7623ad233997dca574ee22e4a
BLAKE2b-256 6a924fcbec114609f67fc50a0901f7befdd773ea18a6524b6ecb1cb0299bd1f3

See more details on using hashes here.

File details

Details for the file cryptanalysis-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cryptanalysis-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ff42b63d0bf2b0ecf748a9cbd6e75e819f7807fab57eb000595d68e48bbd9df5
MD5 ac678bc3869a8e7b8f14f32c08332e8b
BLAKE2b-256 05174489870f6563beaa69a3b183c633f3141bd12068290aa7e4e5100b224c08

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page