I'm trying to reverse a decoding function in order to produce the function for encoding. So far I have ported the decoding function from ASM X86 to Python and it's working fine. My problem is I'm not able to reverse the function because I don't understand what the code does with the bitwise operations. Specially the bitwise OR is like voodoo to me. I'd like some help to simplify/understand the function and reverse it. My code so far: ``` def text_to_hex(text): with open("ENCODE_ARRAY.bin", mode='rb') as file: # b is important -> binary ENCODE_ARRAY = file.read() decoded = [] char_index = 0 i = 0 HARDCODED_LIMIT = 38 while i < HARDCODED_LIMIT: if char_index >= len(text): break current_char_1 = ord(text[char_index]) char_index += 1 eax = ENCODE_ARRAY[current_char_1] if eax == 0xFF: break esi = eax & 0xFF esi *= 2048 if char_index >= len(text): break current_char_2 = ord(text[char_index]) char_index += 1 eax = ENCODE_ARRAY[current_char_2] if eax == 0xFF: break eax = eax & 0xFF esi = esi | (eax * 64) if i >= HARDCODED_LIMIT: break eax = esi eax = eax >> 8 decoded.append(eax) i += 1 if char_index >= len(text): break current_char_3 = ord(text[char_index]) char_index += 1 current_char_3 &= 0xFF eax = ENCODE_ARRAY[current_char_3] if eax == 0xFF: break ebx = eax & 0xFF ebx = (ebx * 2) | esi ebx = ebx * 16777216 if char_index >= len(text): break current_char_4 = ord(text[char_index]) char_index += 1 eax = ENCODE_ARRAY[current_char_4] if eax == 0xFF: break eax = eax & 0xFF ebx = ebx | (eax * 1048576) if i >= HARDCODED_LIMIT: break eax = (ebx >> 0x18) & 0xFF decoded.append(eax) i += 1 if char_index >= len(text): break current_char_5 = ord(text[char_index]) char_index += 1 eax = ENCODE_ARRAY[current_char_5] if eax == 0xFF: break eax = eax & 0xFF ebx = ebx | (eax * 32768) if i >= HARDCODED_LIMIT: break eax = ebx >> 0x10 eax = eax & 0xFF decoded.append(eax) i += 1 if char_index >= len(text): break current_char_6 = ord(text[char_index]) char_index += 1 eax = ENCODE_ARRAY[current_char_6] if eax == 0xFF: break eax = eax & 0xFF ebx = ebx | (eax * 1024) if char_index >= len(text): break current_char_7 = ord(text[char_index]) char_index += 1 eax = ENCODE_ARRAY[current_char_7] if eax == 0xFF: break ebx = ebx | (eax * 32) if i >= HARDCODED_LIMIT: break eax = ebx eax = eax >> 8 eax = eax & 0xFF decoded.append(eax) i += 1 if char_index >= len(text): break current_char_8 = ord(text[char_index]) char_index += 1 eax = ENCODE_ARRAY[current_char_8] if eax == 0xFF: break if i >= HARDCODED_LIMIT: break ebx = ((ebx & 0xFF) | (eax & 0xFF)) decoded.append(ebx) i += 1 return decoded ``` The content of the ENCODE_ARRAY.bin file: ``` FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 01 02 03 04 05 06 07 08 09 FF FF FF FF FF FF FF 0A 0B 0C 0D 0E 0F 10 11 01 12 13 01 14 15 00 16 17 18 19 1A FF 1B 1C 1D 1E 1F FF FF FF FF FF FF 0A 0B 0C 0D 0E 0F 10 11 01 12 13 01 14 15 00 16 17 18 19 1A 1B FF 1C 1D 1E 1F FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ```