Example of Encoded and Encrypted messages
Example of Encoded and Encrypted messages
image from https://secumantra.com
Encoded messages are transformed using a specific algorithm or method to represent data in a different format, often for obfuscation or compression. Here's an example using Base64 encoding:
Original message: "Hello, world!"
Encoded message: "SGVsbG8sIHdvcmxkIQ=="
python
import base64
original_message = "Hello, world!"
encoded_message = base64.b64encode(original_message.encode()).decode()
print("Encoded message:", encoded_message)
Here's an example using symmetric encryption with theA dvanced Encryption Standard (AES) algorithm:
Original message: "Sensitive information"
Key: "mysecretkey"
Encrypted message (in hexadecimal representation): "64c2fc59f91a1d0e1b6db437f3189d47"
python
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes
import binascii
def encrypt_message(message, key):
cipher = AES.new(key.encode(), AES.MODE_CBC, get_random_bytes(AES.block_size))
ciphertext = cipher.encrypt(pad(message.encode(), AES.block_size))
return binascii.hexlify(ciphertext).decode()
def decrypt_message(encrypted_message, key):
cipher = AES.new(key.encode(), AES.MODE_CBC, get_random_bytes(AES.block_size))
decrypted = cipher.decrypt(binascii.unhexlify(encrypted_message))
return unpad(decrypted, AES.block_size).decode()
original_message = "Sensitive information"
key = "mysecretkey"
encrypted_message = encrypt_message(original_message, key)
print("Encrypted message:", encrypted_message)
decrypted_message = decrypt_message(encrypted_message, key)
print("Decrypted message:", decrypted_message)
Comments
Post a Comment