Learn Blockchain | Part 6 #1 | Implementing Multiple Encryption Algorithms Using Python | DES

DES (Data Encryption Standard)

The DES (Data Encryption Standard) algorithm is an algorithm that can be used to encrypt data so that the original data can only be read by someone who has the encryption key. DES used to be a popular encryption algorithm, but due to its size of only 56 bits, it is considered less and less secure to use.

Okay in this tutorial I will use a cryptographic library called pycryptodome, this is a low-level cryptography library that has many encryption algorithm functions.

For how to install it, you can use pip.

pip install pycryptodome

DES (Data Encryption Standard) is a data encryption standard that uses a symmetric encryption algorithm. In this algorithm, the key only has a fixed data block size of 8 bytes. However, the Secret Key used for encryption and decryption is 64 bytes. 56 bytes are generated randomly, and 8 bytes are used for error checking.

Ok, I will show you how to encrypt DES using a python programming language


from Crypto.Cipher import DES
from Crypto.Util.Padding import pad

key = b'th1sK3ys'
data = b'this key will be encrypted'


des = DES.new(key, DES.MODE_ECB)
padded_text = pad(data, BLOK_SIZE)
encrypt = des.encrypt(padded_text)


Value in data will be encrypted as below


Then how do we decrypt it?

The most important thing is that you have the key to decrypt the encrypted data. Decrypting can be likened to opening a locked door, we need a key to open it.

for code like below

key = b'th1sK3ys'
des = DES.new(key, DES.MODE_ECB)
descrypt = des.decrypt(encrypt)


the result is like this, for data that has been encrypted it is returned to its original




b’this key will be encrypted\x06\x06\x06\x06\x06\x06'



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store