Skip to content

The full fledged Data Encryption Standard (DES) πŸ” Algorithm implimented in Python 3 🐍 with detailed explanation and API in Jupyter Notebook πŸ“—.

License

Notifications You must be signed in to change notification settings

anishLearnsToCode/DES

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ— DES (Data Encryption Standard)

made-with-python

Introduction

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:

Running it Locally

Clone this repository on your machine and enter directory.

git clone https://github.com/anishLearnsToCode/DES.git
cd DES

Run the driver.py program to see the output of a number being encrypted and decrypted using DES.

python driver.py
Number: 123456
Encrypted: 7349708071395271833
Decrypyed 123456

The DES algorithm also offers more API endpoints.

Using the API

1. .encrypt(binary: str) -> str

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))

2. .encrypt_number(number: int) -> int

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)

3. .encrypt_message(message: str) -> list[int]

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)

References

  1. Data Encryption Standard ~ Wikipedia
  2. Data Encryption Standard ~ TutorialsPoint
  3. Cryptography and Network Security ~ Behrouz A. Forouzan

About

The full fledged Data Encryption Standard (DES) πŸ” Algorithm implimented in Python 3 🐍 with detailed explanation and API in Jupyter Notebook πŸ“—.

Resources

License

Stars

Watchers

Forks