> 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/xor-decryption/trick-0435.md).

# Decrypt Data Using Single-Byte XOR

***

Perform single-byte XOR decryption using a simple Python script.

```python
def xor_decrypt(data, key):
  return bytes([b ^ key for b in data])

# Define the encrypted byte array (replace with actual data)
encrypted_data = [ ... ]

# Define the single-byte XOR key
key = 125 # Replace with actual key

# Decrypt the data
decrypted_data = xor_decrypt(encrypted_data, key)

# Print the decrypted output, ignoring errors for non-printable characters
print(decrypted_data.decode(errors='ignore'))
```

Replace `encrypted_data` with the bytes you need to decrypt (as a list of integers or bytes) and `key` with the single byte key used for encryption. The script iterates through each byte of the input data, XORs it with the key, and reconstructs the decrypted bytes. The final line attempts to decode the result into a string for printing.

\[Content extension failed: AI response malformed]
