Skip to main content

New : Cipher Breaker, the codebreaking assistant, is now on Android Discover

▮ CipherChronicle

Image methods Scrambling

Keyed XOR

Keyed XOR applies the stream cipher principle to an image: from a key, build a long sequence of random-looking bytes, then combine it with the image. Unlike permutation, it is the values that change, not the positions.

How does keyed XOR work?

XOR (“exclusive or”) compares two bits: it gives 1 if they differ, 0 if they match. Its key property: applying it twice with the same value brings you back to the start.

  1. Derive from the key a stream of pseudo-random bytes as long as the image.
  2. Combine each R, G, B byte of the image with the matching stream byte.
pixel  = 1100 1000   (200)
stream = 0110 1101   (109)
XOR    = 1010 0101   (165)   ← encrypted

cipher = 1010 0101
stream = 0110 1101
XOR    = 1100 1000   (200)   ← recovered

Encrypting and decrypting are therefore the same operation.

What does an XORed image look like?

Like uniform noise, grey on average, with no dominant tint: every value from 0 to 255 becomes equally likely. That is the visible difference with pixel permutation, which keeps the original’s colours.

What are the weaknesses of keyed XOR?

Strengths

  • Flat histogram: the encrypted image says nothing about the original colours.
  • Involutive: one operation for both directions.
  • Fast, and lossless.

Weaknesses

  • Everything rests on the stream. With a non-cryptographic generator, like that of a playful workbench, an attacker can recover the generator state from a few known bytes.
  • Reusing the key is fatal. The XOR of two images encrypted with the same key is the XOR of the two plain images: the stream cancels out and the outlines of both images appear overlaid.
  • Known plaintext: knowing an area of the image (a white background, a banner) gives the stream there directly.
  • Destroyed by JPEG: altering any encrypted byte yields an unrelated value after decryption.
  • Malleable: flipping a ciphertext bit flips the same plaintext bit, with nothing to flag it.

How do you recover the image without the key?

  • Two images, one key: XOR them and read the outlines.
  • Known area: derive the stream, then attack the generator.
  • Weak key: try common words; the right candidate gives an image you recognise at a glance.

With a truly random stream as long as the image and never reused, the method becomes a one-time pad, which is unbreakable. That is the principle behind XOR sharing.

What are the variants of keyed XOR?

  • Repeating key — repeat a short word instead of a stream: very weak, the period shows in the image (the Vigenère equivalent).
  • Permutation then XOR — scramble positions, then values.
  • Chaotic stream — draw the stream from a chaotic sequence (logistic map), very common in the image encryption literature.
  • XOR sharing — the stream becomes a second image handed to someone else.

In CipherChronicle

The workbench asks for a key, XORs the three colour channels and returns an opaque PNG. The same page works both ways. The generator is identical on the site and in the apps, but it is not cryptographic: perfect for a puzzle, not for a secret.

Demonstration

The CipherChronicle artwork is encrypted then decrypted right here, in your browser, with the same engine as the workbench. Drag the bar to compare.