defdecompress(compressed_file, decompressed_file): withopen(compressed_file, "rb") as f: data = f.read()
# Read frequency information frequencies = {} num_of_chars = data[0] i = 1 for j inrange(num_of_chars): char = data[i] freq = ( (data[i + 1] << 24) | (data[i + 2] << 16) | (data[i + 3] << 8) | data[i + 4] ) frequencies[char] = freq i += 5
root = build_huffman_tree(frequencies)
# Read compressed data current_node = root decompressed_data = "" for byte in data[i:]: byte = bin(byte)[2:].rjust(8, "0") for bit in byte: if bit == "0": current_node = current_node.left else: current_node = current_node.right
if current_node.char isnotNone: decompressed_data += chr(current_node.char) current_node = root
# key = b"YOUSHOULDUSETHISTOXORSOMETHING" key = b"youshouldusethistoxorsomething" x = 0x370A05303C290E045005031C2B1858473A5F052117032C39230F005D1E17 xor = bytes([a ^ b for a, b inzip(key, binascii.unhexlify(hex(x)[2:]))]) print(xor) # b'NepCTF{h4ppy_p14N0}NepCTF{h4pp'