A deep dive into breaking repeating-key XOR encryption without knowing the key. The approach involves two steps: first, determining the key length by chunking the ciphertext and finding the chunk length that minimizes the average Hamming Score (normalized Hamming Distance), then brute-forcing all possible keys of that length using letter frequency analysis to identify the most English-like plaintext. The mathematical intuition is explained: when chunk length equals the key length, XORing two chunks cancels out the key, reducing the expression to XOR of plaintext bytes, which have lower Hamming distances since English characters cluster in a narrow numeric range. Python implementations are provided for each step, and the technique achieves ~99% accuracy on random English sentences.

13m read timeFrom arpitbhayani.me
Post cover image
Table of contents
EncryptionDecryptionFinding the length of the Encryption KeyComputing Encryption Key LengthBruteforce to recover the original text
9 Impressions