ALL the CTFS of Crypto2025 finally
This commit is contained in:
25
crypto-simmetric/long-file/chall.py
Normal file
25
crypto-simmetric/long-file/chall.py
Normal 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)]))
|
||||
Reference in New Issue
Block a user