> For the complete documentation index, see [llms.txt](https://sarpers-organization.gitbook.io/ctftricks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sarpers-organization.gitbook.io/ctftricks/_chapter-intro-3/obfuscation/multi-stage-decoding/trick-0076.md).

# Hex & Reverse Base64 Decoding

***

To decode content obfuscated first by hex encoding and then by reversed Base64, first decode the initial hex string.

```bash
echo <hex_string> | xxd -r -p
```

The output of the hex decoding will be a string that is Base64 encoded *in reverse*. Use the following Python script, replacing `<raw_bytes_string>` with the result from the hex decoding step, to reverse the string and then Base64 decode it.

```python
import base64
payload = "<raw_bytes_string>"
rev_payload = payload[::-1]
decoded_payload = base64.b64decode(rev_payload)
print(decoded_payload.decode('utf-8'))
```

This Python script utilizes the standard `base64` module. The `base64.b64decode()` function is used to decode a Base64 encoded bytes-like object or ASCII string and return the decoded bytes. Base64 Decode involves reversing the encoding process to recover the original binary data.
