Question: Assuming there is one client, and one server: 1 . The client acts as the sender , encrypting and encoding the message before sending it

Assuming there is one client, and one server:
1. The client acts as the sender, encrypting and encoding the message before sending it.
2. The client then transmits the encrypted/encoded data to the server. We also assume that the
client and the server had shared the same key "CS645@CS -spring".
3. Finally, when the server receives the message, it appears as
"YidDZHVvQlBURXJNSWVUL0pUK0dEelVJb3VVUEhhdm9xalVUUmZQSzUvZUpua1BvZVFuU2tBL0dndFFNWWZOZm9TJw==".
Please assist the server in recovering the original message. I have already provided the code.
Please fill in the missing content and run it using Python.
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
import os
import base64
def encrypt_message(key, message):
iv = os.urandom(16) # Generate a random IV
padder = padding.PKCS7(128).padder()
padded_data = padder.update(message.encode())+ padder.finalize()
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
encryptor = cipher.encryptor()
ciphertext = encryptor.update(padded_data)+ encryptor.finalize()
return base64.b64encode(iv + ciphertext)
def decrypt_message(key, ciphertext):
data = base64.b64decode(ciphertext)
iv = data[:16]
ciphertext = data[16:]
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
decryptor = cipher.decryptor()
padded_data = decryptor.update(ciphertext)+ decryptor.finalize()
unpadder = padding.PKCS7(128).unpadder()
message = unpadder.update(padded_data)+ unpadder.finalize()
return message.decode()
# Decrypt the message
decrypted_message = decrypt_message(key, encrypted_message)
print("Decrypted:", decrypted_message)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!