Skip to main content

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.

Metadata

Release files for cryptanalysis 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cryptanalysis 0.0.3
File Size Uploaded Provenance Actions
cryptanalysis-0.0.3.tar.gz 30.4 kB Without provenance Details for cryptanalysis-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cryptanalysis 0.0.3
File Interpreter ABI Platform Actions
cryptanalysis-0.0.3-py3-none-any.whl Python 3 none any Details for cryptanalysis-0.0.3-py3-none-any.whl

Total release size: 64.7 kB

Release files / cryptanalysis-0.0.3.tar.gz

Download URL cryptanalysis-0.0.3.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ff4305458d94e7003157549e1807d5c9f57b324de8fc6c3a4f515e9e8ac1bef1
BLAKE2b-256 checksum
How to use checksums
fa31b82aeb7d0fd0bd0a51ea20e1ce769ee28d7cc161fba9ceced0307dc34f74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / cryptanalysis-0.0.3-py3-none-any.whl

Download URL cryptanalysis-0.0.3-py3-none-any.whl
Size 34.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d917aef3c6707c9098b3ded1d9a3af317c66753b825646126665a2624e4232f
BLAKE2b-256 checksum
How to use checksums
cb94a726be6afc6b2812d269da247a21b051d21f3409e787434b2547a0b3206f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for cryptanalysis 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page