ALL the CTFS of Crypto2025 finally

This commit is contained in:
emln
2025-06-02 19:35:30 +02:00
parent aa0fe54b3b
commit 50c18f35b9
442 changed files with 1743 additions and 8 deletions

View File

@ -0,0 +1,25 @@
import os
from Crypto.Cipher import ChaCha20
key = os.urandom(32)
nonce = os.urandom(12)
print(f"Using key: {key.hex()}, nonce: {nonce.hex()}")
with open("./bigfile.txt", "r") as f:
data = f.read().encode()
KEYSTREAM_SIZE = 1000
cipher = ChaCha20.new(key=key, nonce=nonce)
# THe ChaCha20 keystream is repeated each 1000 bytes
keystream = bytes([x ^ y for x, y in zip(
b"\00"*KEYSTREAM_SIZE, cipher.encrypt(b"\00"*KEYSTREAM_SIZE))])
print(len(data))
with open("./file.enc", "wb") as f:
for i in range(0, len(data), KEYSTREAM_SIZE):
f.write(
bytes([p ^ k for p, k in zip(data[i:i+KEYSTREAM_SIZE], keystream)]))