The Data Encryption Standard (DES) is a symmetric-key block cipher published by the National Institute of Standards and Technology (NIST). Here, DES has been implemented in Python 3 with no other dependencies. A full explanation of the cipher along with the Code can be seen in this Jupyter Notebook.
The DES structure uses many smaller Ciphers such as the single Round Fiestel Cipher, which in turn uses the single Swapper and Mixer Ciphers. All of these smaller constructs have lso been built in individual classes and these smaller constructs have been composed together to form the DES Algorithm.
These smaller Ciphers can also be used individual or composed together to create different Ciphers. These building blocks are:
- P-Boxes (Permutation Boxes)
- S-Boxes (Substitution Boxes)
- Swapper Cipher
- Mixer Cipher
- Single Round Fiestel Cipher
- DES (Data Encryption Standard)
Clone this repository on your machine and enter directory.
git clone https://github.com/anishLearnsToCode/DES.git
cd DESRun the driver.py program to see the output of a number being encrypted and decrypted using
DES.
python driver.pyNumber: 123456
Encrypted: 7349708071395271833
Decrypyed 123456The DES algorithm also offers more API endpoints.
This method takes in a binary string with 64 bits and will return a binary encrypted string with 64 bits.
from des import DES
from des.utils import *
des = DES(key=13)
ciphertext = des.encrypt(int_to_bin(12345, block_size=64))
decrypted_binary = des.decrypt(ciphertext)
print('Decrypted:', int(decrypted_binary, base=2))This takes in a 4 Byte unsigned number and returns a 64 bit unsigned encrypted value.
from des import DES
from des.utils import *
des = DES(key=13)
ciphertext = des.encrypt_number(12345)
decrypted = des.decrypt_number(ciphertext)
print('Decrypted:', decrypted)This method takes in a string (character sequence) and returns a list of integers where every integer in the list is an encrypted 64 bit unsigned version of every character in the message string.
from des import DES
from des.utils import *
des = DES(key=13)
ciphertext = des.encrypt_message('hello world π')
decrypted = des.decrypt_message(ciphertext)
print('Decrypted:', decrypted)