Skip to content

Instantly share code, notes, and snippets.

@meysampg
Last active November 30, 2023 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meysampg/96bf138e590ddd773001768867aebf16 to your computer and use it in GitHub Desktop.
Save meysampg/96bf138e590ddd773001768867aebf16 to your computer and use it in GitHub Desktop.
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding
import math
def encrypt_data(data, key, iv):
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
encryptor = cipher.encryptor()
padder = padding.PKCS7(algorithms.AES.block_size).padder()
padded_data = padder.update(data) + padder.finalize()
ciphertext = encryptor.update(padded_data) + encryptor.finalize()
return len(padded_data.hex()), len(ciphertext.hex())
def generate_table():
key = b'1234' * 8
iv = b'1234' * 4
print("| Input Size (Bytes) | Padded Size (Bytes) | Encrypted Size (Bytes) |")
print("|--------------------|----------------------|-------------------------|")
for i in range(1, 11): # Powers of 2 from 2^1 to 2^10
input_size = int(math.pow(2, i))
data = b'a' * input_size # Example data, you can change this
padded_size, encrypted_size = encrypt_data(data, key, iv)
print(f"| {input_size:<18} | {padded_size:<20} | {encrypted_size:<25} |")
if __name__ == "__main__":
generate_table()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment