It uses WebAssembly.instantiate to create a WebAssembly instance. Then, each encoded character is appending to result. We then receive the result.
After some googling, I realised that the bytes given as wasmBuffer is actually a WebAssembly payload which exports a function called encode. After using the wasm2wat tool, I get the following web assembly:
I asked chatGPT to convert this into Python and got the following encoding function:
def encode(data):
for i in range(len(data) - 1):
for j in range(i, len(data) - 1):
data[j + 1] = data[j] ^ data[j + 1]
return data
The encoding function iterates i from from the 0 to n - 1, and for each i it iterates j from i to n - 1. For each j value, the element at index j + 1 is XOR'd with the element at index j. To decode this function we can do the XOR operations in the reverse order.
x = "571653080c6e350c6b0f01196d06436075756365"
ct = [x[i:i+2] for i in range(0, len(x), 2)] # create an array of hex strings
n = len(ct)
for i in range(0, n):
ct[i] = int(ct[i], 16) # convert hex values to ints
for i in range(n - 2, -1, -1):
for j in range(n - 2, i - 1, -1):
ct[j + 1] ^= ct[j] # decode
for i in range(0, n):
ct[i] = chr(ct[i])
print(ct) # CDDC24{WASM_15_R34LY_C00L!!}