Files
crypto2025/decrypt-the-flag/3
2025-04-27 19:24:27 +02:00

34 lines
1.0 KiB
Plaintext

import random
from Cryptodome.Cipher import ChaCha20
from Cryptodome.Util.number import long_to_bytes
#from secret import flag, randkey
nonce = -1
flag = 'Z'*46
randkey= 'A'*32
def encrypt_and_update(msg, nonce):
cipher = ChaCha20.new(key=randkey, nonce=long_to_bytes(nonce))
nonce = random.getrandbits(12*8)
return cipher.encrypt(msg.encode())
def main():
seed = int(input(
"Hi, our system doesn't support analogic entropy... so please give a value to initialize me!\n> "))
random.seed(seed)
nonce = random.getrandbits(12*8)
print("OK! I can now give you the encrypted secret!")
print(encrypt_and_update(flag, nonce).hex())
confirm = input("Do you want to encrypt something else? (y/n)")
while confirm.lower() != 'n':
if confirm.lower() == 'y':
msg = input("What is the message? ")
print(encrypt_and_update(msg, nonce).hex())
confirm = input("Do you want to encrypt something else? (y/n)")
if __name__ == '__main__':
main()