import struct # Open the file for reading in binary mode with open("flag.enc", "rb") as f: # Read the first 4 bytes, which represent the seed seed_bytes = f.read(4) # Unpack the seed as a 32-bit unsigned integer seed = struct.unpack("I", seed_bytes)[0] # Read the rest of the file contents enc_data = f.read() print(f"seed: {seed}, hex: {hex(seed)}") print(f"enc_data: {enc_data}") # Use the seed to seed the random number generator import random random.seed(seed) # Allocate a buffer for the decrypted data dec_data = bytearray(len(enc_data)) # Perform the decryption for i in range(len(enc_data)): # XOR with a random byte dec_data[i] = enc_data[i] ^ random.getrandbits(8) # Perform the inverse bit-shift operation shift = random.randint(0,7) dec_data[i] = ((dec_data[i] >> shift) | (dec_data[i] << (8 - shift))) % 256 print(f"flag: {dec_data}") # Write the decrypted data to a file # with open("flag.dec", "wb") as f: # f.write(dec_data)