Lab Icon

XOR Reuse

Can you break this cipher with just a few known bytes?

Challenge Updated 22 Jun 2026 Solution (Pro)
Cryptography XOR Known-Plaintext Attack Hex Encoding

A secret was encrypted with repeating-key XOR, one of the oldest tricks in the book. The key is short and it cycles. If you can figure out the format of the original message, you already know enough to crack the whole thing. Time to think like a cryptanalyst.

1
Flags
50
XP
43%
Success Rate

XOR (exclusive or) encryption is one of the simplest and most fundamental operations in cryptography. While XOR itself is a perfectly valid building block used in modern ciphers like AES, its misuse - particularly repeating a short key across a long message - creates a classic vulnerability that has compromised countless systems. Understanding the known-plaintext attack against repeating-key XOR is foundational knowledge for any aspiring cryptographer or security professional.

How XOR Encryption Works

The XOR operation compares two bits and returns 1 when they differ, 0 when they match. Its critical property for cryptography is that it is its own inverse: if A XOR B = C, then C XOR B = A and C XOR A = B. This means the same operation encrypts and decrypts. To encrypt a message, each byte of plaintext is XORed with a corresponding byte of the key. With a truly random key that is as long as the message and never reused (a one-time pad), XOR encryption is mathematically unbreakable.

The vulnerability arises when developers use a short key that repeats across the entire message. If the key is "KEY" (3 bytes), the first plaintext byte is XORed with K, the second with E, the third with Y, the fourth with K again, and so on. This repetition creates patterns that attackers can exploit. Any known or guessable portion of the plaintext directly reveals the corresponding key bytes, and since the key repeats, those revealed bytes decrypt every position that uses the same key offset.

The Known-Plaintext Attack

In a known-plaintext attack, the attacker leverages knowledge about the message format to recover the key. Many file formats and protocols have predictable headers, standard prefixes, or common structures. For example, if the attacker knows the plaintext starts with "HTTP/1.1" or contains a flag format like "FLAG{", XORing those known bytes with the corresponding ciphertext bytes reveals the key. With the key recovered, the entire message can be decrypted.

Lessons for Modern Cryptography

The weakness of repeating-key XOR illustrates why modern encryption algorithms use complex key scheduling, unique initialization vectors, and authenticated encryption modes. It demonstrates that the security of a cipher depends not just on the operation used but on how the key material is managed. These principles underpin AES-GCM, ChaCha20-Poly1305, and other algorithms trusted for securing internet communications today.

What You Will Learn

  • Understand XOR encryption mechanics at the byte level
  • Learn why repeating short keys creates exploitable patterns
  • Master the known-plaintext attack technique for key recovery
  • Practice hex encoding and ASCII conversion for cryptographic analysis
  • Develop foundational cryptanalysis skills applicable to modern cipher weaknesses

Prerequisites

Basic understanding of binary and hexadecimal Familiarity with a scripting language (Python recommended) Understanding of basic encryption concepts

Ready to hack this lab?

Create a free account and start practicing cybersecurity hands-on.

Start Hacking - It's Free
Start Your Challenge
~1-2 min setup
Dedicated server
Private instance
Standard power
New here? Here's what to do
1
Click "Start Lab" above You'll get your own private machine with an IP address
2
Explore the target Open the IP in your browser and look for vulnerabilities
3
Find and submit flags Flags are secret text strings hidden in the system - paste them below to score

Ready to hack this lab?

Create a free account to start your own dedicated server, submit flags, and earn XP on the leaderboard.

Start Hacking Free
13,000+ Hackers 100+ Labs & Courses Free
Start Hacking Free