- 31st Jul 2024
- 18:07 pm
In this assignment, we provide comprehensive solutions for encryption and decryption using Python, focusing on three key algorithms: DES, AES, and CBC. Each algorithm is implemented in separate files for clarity and ease of use. This detailed approach ensures a solid understanding of these cryptographic techniques and their practical applications. The assignment as illustrated as following - Encrypt and decrypt and please keep every one in separate file. 1- Encryption and Decryption the DES algorithm in Python. 2- Encryption and Decryption the AES algorithm in Python. 3- Encryption and Decryption the CBC algorithm in Python.
Free Assignment Solution - Encryption And Decryption Algorithms In Python: DES, AES, and CBC
Encryption and Decryption the DES algorithm in Python
# Installation of Dependencies
!pip3 install pycrypto
!pip3 install base32hex
# Importing the necessary Files
import base32hex
import hashlib
from Crypto.Cipher import DES
# Initialising Key
key = b'hello123'
def pad(text):
n = len(text) % 8
return text + (b' ' * n)
# It will encrypte the Text into DES Encrypted texts
def encryptByDES(plain_text):
text1 = bytes(plain_text, 'utf-8')
des = DES.new(key, DES.MODE_ECB)
padded_text = pad(text1)
encrypted_text = des.encrypt(padded_text)
print(encrypted_text)
# print(des.decrypt(encrypted_text))
return encrypted_text
# It will decrypt the encrypted DES Text to normal one
def decryptByDES(plain_text):
des = DES.new(key, DES.MODE_ECB)
padded_text = pad(plain_text)
decryptText=des.decrypt(plain_text).decode('utf-8')
print(decryptText)
return decryptText
# Executing encrypt and decrypt
returnValue=encryptByDES("Python is the Best Language!")
decryptByDES(returnValue)
Encryption and Decryption the AES algorithm in Python
# Installation of Dependencies
!pip3 install pycrypto
!pip3 install base32hex
# Importing the necessary Files
import base32hex
import hashlib
from Crypto.Cipher import AES
from os import urandom
# Initialising Key
# key = b'hello123'
secret_key = urandom(16)
iv = urandom(16)
def pad(text):
n = len(text) % 8
return text + (b' ' * n)
# It will encrypte the Text into DES Encrypted texts
def encryptByAES(plain_text):
text1 = bytes(plain_text, 'utf-8')
aes = AES.new(secret_key, AES.MODE_ECB,iv)
padded_text = pad(text1)
encrypted_text = aes.encrypt(padded_text)
print(encrypted_text)
# print(des.decrypt(encrypted_text))
return encrypted_text
# It will decrypt the encrypted DES Text to normal one
def decryptByAES(plain_text):
aes = AES.new(secret_key, AES.MODE_ECB,iv)
padded_text = pad(plain_text)
decryptText=aes.decrypt(plain_text).decode('utf-8')
print(decryptText)
return decryptText
# Executing encrypt and decrypt
returnValue=encryptByAES("Python is the Best Language!")
decryptByAES(returnValue)
Encryption and Decryption the CBC algorithm in Python
# Installation of Dependencies
!pip3 install pycrypto
!pip3 install base32hex
# Importing the necessary Files
import base32hex
import hashlib
from Crypto.Cipher import AES
from os import urandom
# Initialising Key
# key = b'hello123'
secret_key = urandom(16)
iv = urandom(16)
def pad(text):
n = len(text) % 8
return text + (b' ' * n)
# It will encrypte the Text into DES Encrypted texts
def encryptByCBC(plain_text):
text1 = bytes(plain_text, 'utf-8')
cbc = AES.new(secret_key, AES.MODE_CBC,iv)
padded_text = pad(text1)
encrypted_text = cbc.encrypt(padded_text)
print(encrypted_text)
# print(des.decrypt(encrypted_text))
return encrypted_text
# It will decrypt the encrypted DES Text to normal one
def decryptByCES(plain_text):
cbc = AES.new(secret_key, AES.MODE_CBC,iv)
padded_text = pad(plain_text)
decryptText=cbc.decrypt(plain_text).decode('utf-8')
print(decryptText)
return decryptText
# Executing encrypt and decrypt
returnValue=encryptByCBC("Python is the Best Language!")
decryptByCES(returnValue)
Get the best Encryption And Decryption Algorithms In Python: DES, AES, and CBC assignment help and tutoring services from our experts now!
Our team of Python experts has successfully finished this sample Python assignment. The provided solutions are intended solely for research and reference. If you find the reports and code useful, our Python tutors would be happy to help.
- For a complete solution package that includes code, reports, and screenshots, please check out our Python Assignment Sample Solution page.
- For personalized online tutoring sessions to address any questions you have about this assignment, reach out to our Python experts.
- For additional insights, explore the partial solution available in the blog above.
About The Author - Alex Carter
Alex Carter is a seasoned cybersecurity professional and Python developer with expertise in cryptographic algorithms. With a deep understanding of DES, AES, and CBC encryption techniques, Alex excels in creating practical solutions and clear implementations. His work simplifies complex encryption and decryption processes, offering valuable insights for academic and professional projects.