des_PurePy.des module

Module providing a DES class for a DES implementation

class des_PurePy.des.DES(key)

Bases: object

Implements the Data Encryption Standard (DES).

A DES object is initialized with a 64-bit key and can be used repeatedly to encrypt or decrypt data.

Parameters:

key (str or bytes) – The DES key. May be given as a hexadecimal string (with or without a 0x prefix) or as a bytes object.

Methods

decrypt(ciphertext)

Decrypts the input ciphertext by key according to DES

encrypt(plaintext)

Encrypts the input plaintext by key according to DES

decrypt(ciphertext) str

Decrypts the input ciphertext by key according to DES

Parameters:

ciphertext (hex string or bytes object) – Ciphertext to be encrypted. Can be a string representing a hex number or a bytes object. Hex strings can have a leading ‘0x’ and are case-insensitive. ciphertext length should be a multiple of the block size (64 bits)

Returns:

cleartext – Decrypted cleartext as a hex number. Has a leading ‘0x’.

Return type:

str

encrypt(plaintext) str

Encrypts the input plaintext by key according to DES

Parameters:

plaintext (hex string or bytes object) – Plaintext to be encrypted. Can be a string representing a hex number or a bytes object. Hex strings can have a leading ‘0x’ and are case-insensitive. plaintext can be any length.

Returns:

ciphertext – Encrypted ciphertext as a hex number. Has a leading ‘0x’. Length can vary according to length of input. Will always be a multiple of the block size.

Return type:

str

key

Key to be used for encrypting or decrypting. Can be a string representing a hex number or a bytes object. Hex strings can have a leading ‘0x’ and are case-insensitive. key should be exactly the key size for DES (64 bits)