Skip to main content

A pure python implementation of DES

Project description

DES-Python

made-with-python license: AGPL-3.0 DES-Python PyPI Downloads

Data Encryption Standard (DES) implemented in pure Python

Demo

Features

  • Encryption and Decryption
  • PKCS5 Padding
  • ECB Mode of Operation
  • Hex String and Bytes Object Support

Installation

Install using your Python package manager of choice:

pip install des_PurePy

Usage

Encrypting Hex Strings

Define a DES object while passing in your key. The key can be a hex string or a bytes object.

import des_PurePy
des = des_PurePy.DES("0x133457799bbcdff1")

You can encrypt by calling encrypt() and passing in a hex string or bytes object.

des.encrypt("0x0123456789abcdef")    # -> "0x85e813540f0ab405fdf2e174492922f8"

You can simarly decrypt by calling decrypt() and passing in a hex string or bytes object.

des.decrypt("0x85e813540f0ab405fdf2e174492922f8")    # -> "0x0123456789abcdef"

By default, encryption input is padded to a multiple of the block size (8 bytes) according to PKCS5. Inputs that are multiple blocks long are encrypted using the Electronic Code Book (ECB) mode of operation.

Encrypting Bytes Objects and Text

Inputs can be hex strings or bytes objects. The key must always be 8 bytes but the encryption input can have any size. Because of the bytes object support, with some work, you can encrypt and decrypt text.

import des_PurePy

key = b"password"
des = des_PurePy.DES(key)

ciphertext = des.encrypt(b"secret message")                 # -> "0x0d417ca7d23582bab5e2c9277f801591"
cleartext = des.decrypt(ciphertext)                         # -> "0x736563726574206d657373616765"
cleartext = bytes.fromhex(cleartext[2:]).decode("utf-8")    # -> "secret message"

Note that all input is validated so if you pass in an inapropriate input the module will raise a corresponding error.

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

des_purepy-1.0.14.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

des_purepy-1.0.14-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file des_purepy-1.0.14.tar.gz.

File metadata

  • Download URL: des_purepy-1.0.14.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for des_purepy-1.0.14.tar.gz
Algorithm Hash digest
SHA256 2dca089fbe8bc8a5473f7ce2368bbcd22b6215d2d73b632eb198d1e1238f121f
MD5 77bbd0a6a359736cd4768128d1a5a598
BLAKE2b-256 ac31f13e27df258d7ee7e79cd1297bd3966f267153c2487d88100f32ab61a7f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for des_purepy-1.0.14.tar.gz:

Publisher: release.yaml on Perez-Herrera-Luna/DES-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file des_purepy-1.0.14-py3-none-any.whl.

File metadata

  • Download URL: des_purepy-1.0.14-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for des_purepy-1.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 896a6a0dda8d12b86310bc87345b642320af646b8df19bd23c2fdb7f96727044
MD5 e232a8d45447f2bf51e55ef56f3951d2
BLAKE2b-256 9c940dea6a051b58138dd3f9cf2c5cc5daa73169965a32f8568d21ee38c1b0c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for des_purepy-1.0.14-py3-none-any.whl:

Publisher: release.yaml on Perez-Herrera-Luna/DES-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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