This guide uses a known key and original learning data. With Hex input 40 43 42 and Hex key 01, XOR produces bytes 41 42 43, which read as ABC in UTF-8. The task is to apply a supplied key correctly, rather than discover an unknown one.
The XOR truth table
Exclusive OR compares two corresponding bits. Different bits produce 1; equal bits produce 0.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
For a byte example, Hex 40 is binary 01000000, and key 01 is 00000001. Only the lowest bit changes. The result is 01000001, or Hex 41.
Why the same key restores the input
A key bit of 0 leaves a data bit unchanged. A key bit of 1 flips it. Flipping the same positions again restores the original, so (data XOR key) XOR key = data.
The UTF-8 bytes of ABC are 41 42 43. Applying key 01 to each byte produces 40 43 42; applying that key again returns 41 42 43. Encoding and decoding use the same XOR operation.
Recover ABC in the tool
- Open the XOR calculator.
- Select Hex for both Input format and Key format.
- Enter key
01and input40 43 42, then select Convert. - Check the text output
ABCand the Hex byte output41 42 43.
To try the reverse, change the input format to UTF-8 and enter ABC. Keep the key as Hex 01. The text output is @CB, and its Hex representation is 40 43 42. Use the Hex output with Hex input mode when reversing the calculation to avoid mixing representations.
Hex keys and UTF-8 keys differ
The visible value 01 can describe different key bytes.
| Setting | Actual key bytes | Length |
|---|---|---|
Hex 01 |
01 |
One byte |
UTF-8 01 |
30 31 |
Two bytes |
UTF-8 A |
41 |
One byte |
The first row means a byte with value 1. The second means the characters 0 and 1. If the same-looking key gives an unexpected result, check its selected format. The Hex and UTF-8 guide explains the underlying character-to-byte mapping.
Repeating keys and alignment
Tools Hub repeats the key bytes if the key is shorter than the input. For data 41 42 43 and key 01 02, the applied key sequence is 01 02 01, producing 40 40 42.
If you copy only the middle of a message, the key may need a different starting position. This calculator always aligns the first input byte with the first key byte. Check the exercise specification when working with a different alignment or key schedule.
Troubleshoot unreadable output
XOR produces bytes, which do not necessarily represent text. Tools Hub warns when output is invalid UTF-8 while retaining a Hex byte view. For example, input ff with key 00 remains ff: a valid byte, but not valid UTF-8 text.
Check the key, both formats, repetition and alignment. If those match, the expected output might be a file or another encoded representation. Unreadable text alone does not prove that the key is wrong.
The calculator does not recover unknown keys. Short repeating-key XOR is unsuitable for protecting secrets. Use the XOR calculator to compare bytes with explicitly selected input and key formats.