Encrypting and decrypting with the DES algorithm

DES is a block cipher, which means that the text to be encrypted is a multiple of eight, so I added spaces at the end of the text. When I deciphered it, I removed them.

The following script encrypts a user and a password and, finally, simulating that it is the server that has received these credentials, decrypts and displays this data.

You can find the following code in the Encrypt_decrypt_DES.py file inside the pycrypto folder:

from Crypto.Cipher import DES# How we use DES, the blocks are 8 characters# Fill with spaces the user until 8 charactersuser =  "user    "password = "password"# we create the cipher with DEScipher = DES.new('mycipher')# encrypt username and passwordcipher_user = cipher.encrypt(user) ...

Get Mastering Python for Networking and Security now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.