Skip to content

Instantly share code, notes, and snippets.

@delivrance
Last active August 10, 2022 02:09
Show Gist options
  • Save delivrance/41cf5c5be6ff78aa9c0d8a7db0ea37b8 to your computer and use it in GitHub Desktop.
Save delivrance/41cf5c5be6ff78aa9c0d8a7db0ea37b8 to your computer and use it in GitHub Desktop.
TgCrypto benchmark
# https://github.com/pyrogram/tgcrypto
import os
import time
import tgcrypto
def fmt(d, s):
return f"{len(d) / (time.time() - s) / 1024 / 1024 :.2f} MB/s"
data = os.urandom(50 * 1024 * 1024)
key = os.urandom(32)
iv = os.urandom(32)
start = time.time()
tgcrypto.ige256_encrypt(data, key, iv)
print(f"IGE Enc: {fmt(data, start)}")
start = time.time()
tgcrypto.ige256_decrypt(data, key, iv)
print(f"IGE Dec: {fmt(data, start)}")
print()
start = time.time()
tgcrypto.ctr256_encrypt(data, key, iv[:16], bytes(1))
print(f"CTR Enc: {fmt(data, start)}")
start = time.time()
tgcrypto.ctr256_decrypt(data, key, iv[:16], bytes(1))
print(f"CTR Dec: {fmt(data, start)}")
print()
start = time.time()
tgcrypto.cbc256_encrypt(data, key, iv[:16])
print(f"CBC Enc: {fmt(data, start)}")
start = time.time()
tgcrypto.cbc256_decrypt(data, key, iv[:16])
print(f"CBC Dec: {fmt(data, start)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment