cryptanalysis


Namecryptanalysis JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/deut-erium/auto-cryptanalysis
SummaryAutomated cryptanalysis library for substitution permutation network
upload_time2023-08-27 21:49:30
maintainer
docs_urlNone
authorHimanshu Sheoran
requires_python>=3.6
licenseGPL
keywords cryptanalysis differential linear cryptography spn cipher crypto
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```bash
pip install cryptanalysis
```

Otherwise clone and install is also viable

```bash
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:
```bash
pip install -r requirements.txt
```

## Usage
```python
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:
```bash
python -m unittest discover
```

## Documentation
Read the [documentation](https://deut-erium.github.io/auto-cryptanalysis)  
Autogenerated documentation from code doc-strings can be found under [docs](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](CONTRIBUTING.md)

## License
This project is licensed under the GPL License.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/deut-erium/auto-cryptanalysis",
    "name": "cryptanalysis",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "cryptanalysis differential linear cryptography SPN cipher crypto",
    "author": "Himanshu Sheoran",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/fa/31/b82aeb7d0fd0bd0a51ea20e1ce769ee28d7cc161fba9ceced0307dc34f74/cryptanalysis-0.0.3.tar.gz",
    "platform": null,
    "description": "# Auto Cryptanalysis\nThis project implements python module for automatic cryptanalysis of Substitution Permutation Network\nciphers by performing extensive linear and differential characteristic search and finding keybits\n\n## Structure\nThe project is structured as follows:\n\n- The `cryptanalysis` directory contains the main Python module for cryptanalysis.\n- The `tests` directory contains unit tests for the module\n- The `examples` directory contains examples for using the module\n- The `docs` directory contains html documentation autogenerated from code doc-strings\n\n## Installation\n\n### Pip\nThe project can be installed directly from pip\n```bash\npip install cryptanalysis\n```\n\nOtherwise clone and install is also viable\n\n```bash\ngit clone https://github.com/deut-erium/auto-cryptanalysis.git\ncd auto-cryptanalysis\npip install .\n```\n\n### Requirements\nThis project requires Python3.6+ and the following Python packages:\n- z3-solver\n- tqdm\n\nRequirements are auto installed as a part of the installation process but\n\nYou can also install these packages using pip:\n```bash\npip install -r requirements.txt\n```\n\n## Usage\n```python\nimport random\nimport cryptanalysis\n\nsbox_size = 6 # bits\npbox_size = sbox_size * 16 # 16 sboxes\nnum_rounds = 4\nsbox = list(range(2**sbox_size))\npbox = list(range(pbox_size))\n# random pbox and sbox\nrandom.shuffle(sbox)\nrandom.shuffle(pbox)\n\nrandom_key = random.randint(0, (2**pbox_size) - 1)\n# random spn instance whose key is unknown to us\nspn = cryptanalysis.SPN(sbox, pbox, random_key, num_rounds)\n\nd_c = cryptanalysis.differential_cryptanalysis.DifferentialCryptanalysis(sbox, pbox, num_rounds+1)\n# override batch_encrypt with the oracle\n\nmax_num_encryptions = 50000\ndef batch_encrypt(plaintexts):\n    return [spn.encrypt(i) for i in plaintexts]\n\nd_c.batch_encrypt = batch_encrypt\ndifferential_characteristics = d_c.characteristic_searcher.search_exclusive_masks()\nlast_round_key_blocks = d_c.find_last_roundkey(differential_characteristics, max_num_encryptions//16)\n\nprint(\"recovered last round key:\",last_round_key_blocks)\nprint(\"original last round key:\",d_c.int_to_list(spn.round_keys[-1]))\n```\n\n## Tests\nYou can run the tests using the following command:\n```bash\npython -m unittest discover\n```\n\n## Documentation\nRead the [documentation](https://deut-erium.github.io/auto-cryptanalysis)  \nAutogenerated documentation from code doc-strings can be found under [docs](docs)  \n\n## Contributing\nPlease feel free to submit pull requests or create issues if you find any bugs or have any suggestions for improvements.  \nList of ideas to implement/TODO is present in [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## License\nThis project is licensed under the GPL License.\n\n\n",
    "bugtrack_url": null,
    "license": "GPL",
    "summary": "Automated cryptanalysis library for substitution permutation network",
    "version": "0.0.3",
    "project_urls": {
        "Documentation": "https://deut-erium.github.io/auto-cryptanalysis",
        "Homepage": "https://github.com/deut-erium/auto-cryptanalysis",
        "Source Code": "https://github.com/deut-erium/auto-cryptanalysis"
    },
    "split_keywords": [
        "cryptanalysis",
        "differential",
        "linear",
        "cryptography",
        "spn",
        "cipher",
        "crypto"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cb94a726be6afc6b2812d269da247a21b051d21f3409e787434b2547a0b3206f",
                "md5": "33103356ec0cb606d9393de348b100c3",
                "sha256": "3d917aef3c6707c9098b3ded1d9a3af317c66753b825646126665a2624e4232f"
            },
            "downloads": -1,
            "filename": "cryptanalysis-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "33103356ec0cb606d9393de348b100c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 34316,
            "upload_time": "2023-08-27T21:49:28",
            "upload_time_iso_8601": "2023-08-27T21:49:28.496380Z",
            "url": "https://files.pythonhosted.org/packages/cb/94/a726be6afc6b2812d269da247a21b051d21f3409e787434b2547a0b3206f/cryptanalysis-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa31b82aeb7d0fd0bd0a51ea20e1ce769ee28d7cc161fba9ceced0307dc34f74",
                "md5": "281edc0d9480e53934bc48e411c9a7e1",
                "sha256": "ff4305458d94e7003157549e1807d5c9f57b324de8fc6c3a4f515e9e8ac1bef1"
            },
            "downloads": -1,
            "filename": "cryptanalysis-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "281edc0d9480e53934bc48e411c9a7e1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 30375,
            "upload_time": "2023-08-27T21:49:30",
            "upload_time_iso_8601": "2023-08-27T21:49:30.378523Z",
            "url": "https://files.pythonhosted.org/packages/fa/31/b82aeb7d0fd0bd0a51ea20e1ce769ee28d7cc161fba9ceced0307dc34f74/cryptanalysis-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-27 21:49:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deut-erium",
    "github_project": "auto-cryptanalysis",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "cryptanalysis"
}
        
Elapsed time: 0.10592s