0% found this document useful (0 votes)
6 views2 pages

Data Encryption Standard

Uploaded by

Pritish Dighore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Data Encryption Standard

Uploaded by

Pritish Dighore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Encryption Standard

Program:
from Cryptodome.Cipher import DES

from Cryptodome.Util.Padding import pad, unpad

from Cryptodome.Random import get_random_bytes

# Example user message

user_message = "This sentence for prashik"

# Convert message to bytes

user_message_bytes = user_message.encode('utf-8')

# Generate a random 8-byte (64-bit) DES key

key = get_random_bytes(8) # DES uses a 56-bit key, but 8 bytes (64 bits) are stored

# Create a DES cipher object in ECB (Electronic Codebook) mode

cipher = DES.new(key, DES.MODE_ECB)

# Padding the message to make it a multiple of 8 bytes (64 bits)

padded_message = pad(user_message_bytes, DES.block_size)

# Encrypt the message

ciphertext = cipher.encrypt(padded_message)

print(f"Original message: {user_message}")

print(f"Encrypted message: {ciphertext.hex()}")


# Decrypting the message

decipher = DES.new(key, DES.MODE_ECB)

decrypted_padded_message = decipher.decrypt(ciphertext)

# Unpadding the decrypted message

decrypted_message = unpad(decrypted_padded_message, DES.block_size)

print(f"Decrypted message: {decrypted_message.decode('utf-8')}")

Output:

You might also like