Skip to main content

Maintenance made-with-python PyPI pyversions PyPI version PyPI status GitTutorial Downloads

DESfiddle

A simple to use python package for implementing and experimenting with the famous DES encryption algorithm. It implements both classical (default settings from the textbook description of DES) and non-classical DES. Check out DES app for a very specific implementation demonstrating avalanche effect and weak keys using the package.

Motivation

There are quite a few DES packages for python but none of them offer such high flexibility to implement a non-classical version of the DES. This package is aimed specifically to experiment with the different hyperparamters that can be tweaked while implementing DES.

Features

  • Only package till date to implement a non-classical version of DES.
  • Lots of hyperparameters* to tweak-
    • Number of rounds
    • Halfwidth for plaintext & key
    • Hamming distance for plaintext & key
    • Permutation boxes (Initial, Final & Inverse)
    • Shift arrays
    • S-boxes
    • Expansion box
  • Implementing classical DES is as easy as leaving the hyperparameters to their default values and the rest will be taken care of automatically.
  • Each function has a detailed doc string attached to it, thus minimising the need to navigate to the docs for usage referencing. So, if you quickly wanna see the function description just type in help(<function_name>) in the python interpreter.

Bonus: This package can be a life-saver for CSE 537- Network Security course taught at IIT (BHU).

*Tweaking some of these may require changing the source code as of the current release

Installation

Run the following command in your terminal/command prompt-

$ pip install DESfiddle

Note: If you dont have pip installed, follow these steps.

Importing and Usage

# Importing
import DESfiddle.utils as dfu

# Usage
permutation_arr = dfu.generate_permutation(64)
# Importing
from DESfiddle.utils import *
# or just specify the function name you wanna import

# Usage
permutation_arr = generate_permutation(64)

Code Examples

from DESfiddle.utils import *

# Inputs in binary setting
plaintext = "0101010101010101010101010101010101010101010101010101010101010101"
key = "1111111111111111111111111111111100000000000000000000000000000000"

# Settings
nor = 16
halfwidth = 32
hamming_dist = 1

# Hamming the plaintext in binary mode
ref_pt_arr = preprocess_plaintext(plaintext, halfwidth)
pt_arr = preprocess_plaintext(plaintext, halfwidth, hamming_dist)
key = preprocess_key(key, halfwidth)
rkb,rkh = generate_round_keys(key,nor, halfwidth)
ref_ciphertext, ref_round_ciphertexts = encrypt(ref_pt_arr, rkb, nor, halfwidth)
_, round_ciphertexts = encrypt(pt_arr, rkb, nor, halfwidth)
diff = calc_diff(ref_round_ciphertexts, round_ciphertexts)

# Hamming the key in binary mode
pt_arr = preprocess_plaintext(plaintext, halfwidth)
ref_key = preprocess_key(key,halfwidth)
key = preprocess_key(key, halfwidth, hamming_dist)
ref_rkb, ref_rkh = generate_round_keys(ref_key, nor, halfwidth)
rkb,_ = generate_round_keys(key, nor, halfwidth)
ref_ciphertext, ref_round_ciphertexts = encrypt(pt_arr, ref_rkb, nor, halfwidth)
_, round_ciphertexts = encrypt(pt_arr, rkb, nor, halfwidth)
diff = calc_diff(ref_round_ciphertexts, round_ciphertexts)
from DESfiddle.utils import *

# Inputs in ASCII setting
plaintext = "This is so cool"
key = "Yesss"

# Settings
nor = 16
halfwidth = 32
hamming_dist = 1

# Preprocessing when input in ASCII
plaintext = txt_to_hex(plaintext)
plaintext = hex_to_bin(plaintext)
key = txt_to_hex(key)
key = hex_to_bin(key)

# Hamming the plaintext in binary mode
ref_pt_arr = preprocess_plaintext(plaintext, halfwidth)
pt_arr = preprocess_plaintext(plaintext, halfwidth, hamming_dist)
key = preprocess_key(key, halfwidth)
rkb,rkh = generate_round_keys(key,nor, halfwidth)
ref_ciphertext, ref_round_ciphertexts = encrypt(ref_pt_arr, rkb, nor, halfwidth)
_, round_ciphertexts = encrypt(pt_arr, rkb, nor, halfwidth)
diff = calc_diff(ref_round_ciphertexts, round_ciphertexts)

# Hamming the key in binary mode
pt_arr = preprocess_plaintext(plaintext, halfwidth)
ref_key = preprocess_key(key,halfwidth)
key = preprocess_key(key, halfwidth, hamming_dist)
ref_rkb, ref_rkh = generate_round_keys(ref_key, nor, halfwidth)
rkb,_ = generate_round_keys(key, nor, halfwidth)
ref_ciphertext, ref_round_ciphertexts = encrypt(pt_arr, ref_rkb, nor, halfwidth)
_, round_ciphertexts = encrypt(pt_arr, rkb, nor, halfwidth)
diff = calc_diff(ref_round_ciphertexts, round_ciphertexts)

Contributing Guidelines

Thanks for taking the time to contribute!

The following is a set of guidelines for contributing to DESfiddle. These are just guidelines, not rules, so use your best judgement and feel free to propose changes to this document in a pull request.

Getting Started

DESfiddle is built over python. So if you are new to python, please head over to this great website.

Community

  • The whole DESfiddle documentation, such as setting up a development environment, the project, and testing, can be read here.
  • If you have any questions regarding DESfiddle, open an issue or ask it directly on Linkedin.

Issue

Ensure the bug was not already reported by searching on GitHub under issues. If you're unable to find an open issue addressing the bug, open a new issue.

Write detailed information

Detailed information is very helpful to understand an issue, for example-

  • How to reproduce the issue, step-by-step.
  • The expected behavior (or what is wrong).
  • Screenshots for GUI issues.
  • The application version.
  • The operating system.
  • The DESfiddle version.

Pull requests

Pull Requests are always welcome.

  • When you edit the code, please run python -m unittest to test your code before you git commit.
  • Ensure the PR description clearly describes the problem and solution. It should include-
    • The operating system used while testing
    • DESfiddle version number
    • The relevant issue number, if applicable.

Version

Follows syntax vM.M.P First is major and means not backwards compatible changes. Second is minor and means backwards compatible changes. Third is patch and means small backwards compatible changes.

The manual place of source of truth for the version is at setup.py

Metadata

Release files for DESfiddle 1.0.0

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

Source distribution (sdist)

Source distribution for DESfiddle 1.0.0
File Size Uploaded
DESfiddle-1.0.0.tar.gz 9.9 kB Details

Built distribution (wheel)

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

Total release size: 19.0 kB

Release files / DESfiddle-1.0.0.tar.gz

Download URL DESfiddle-1.0.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ff82eea8e20906bebdf8c12e86cffa2a949d140c81436fe08a8e4578cdf9f3cc
BLAKE2b-256 checksum
How to use checksums
37112c360c41f94ec00abb70b68a41ccfcc0b63068d1f33a94a15ceb57dec869
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / DESfiddle-1.0.0-py3-none-any.whl

Download URL DESfiddle-1.0.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a8ff9afeb4b41346d11fbebc42c2b119b9242209aca8ce5d472bf7ff1d6aeed
BLAKE2b-256 checksum
How to use checksums
c1de8de5f8863ccdc64e9c60116e88d5bf15325b61de8b7fb30552394d44705a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.10

2 release files

0.0.9

2 release files

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