Skip to main content

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

▮ CipherChronicle

Image methods Scrambling

Colour substitution

Colour substitution is to an image what a monoalphabetic substitution is to text: instead of replacing each letter with another, each colour value is replaced with another. It is the exact counterpart of pixel permutation: there positions change and values stay, here it is the other way round.

How does colour substitution work?

Each channel of a pixel ranges from 0 to 255. From the key, three 256-entry tables are built (one for red, one for green, one for blue), each a shuffle of the numbers 0 to 255.

  1. Derive from the key a pseudo-random sequence and use it to shuffle each table.
  2. Replace: for each pixel, the red value v becomes tableR[v], and likewise for green and blue.
tableR:  0→143   1→27   2→201   …   200→64   …
red pixel = 200   →   64

To decrypt, regenerate the same tables and read them backwards: 64 → 200. Since each table is a permutation, no value is lost.

What does a colour-substituted image look like?

Like a psychedelic negative. Two pixels of the same colour get the same new colour: a flat area stays flat, an edge stays an edge. A logo or a piece of text remains perfectly readable, just in other hues.

Gradients, however, are shattered: two neighbouring values (200 and 201) are sent to two unrelated values. A graded sky turns into banded noise.

What are the weaknesses of colour substitution?

Strengths

  • Lossless: with the right key, the image comes back exactly.
  • Very fast: one table lookup per value.
  • Scrambled histogram: the proportions of each colour are kept, but not the colours themselves.

Weaknesses

  • Shapes stay visible. This is the flaw of any monoalphabetic substitution: the structure of the message survives. For a logo, a diagram or text, the method hides next to nothing.
  • Vulnerable to known plaintext. Knowing the original colour of an area gives table entries directly.
  • Vulnerable to the regularity of images. In a photo, two neighbouring pixels nearly always have neighbouring values: that constraint is enough to rebuild the table step by step.
  • Destroyed by JPEG: an encrypted value off by 1 decrypts to an arbitrary colour.

How do you recover the image without the key?

  1. Look: often the image is already understandable as is.
  2. Use neighbourhoods: for each channel, record which encrypted values appear side by side. In the original image, values that are close in space are close in number: this orders the 256 encrypted values into a chain, which gives the table back up to a reversal (light ↔ dark).
  3. Pin the extremes with a known area: a sky, a white background, a shadow.

This is the analogue of frequency analysis against a letter substitution: the method breaks because the message is redundant.

What are the variants of colour substitution?

  • Shift (Caesar on pixels) — add a constant modulo 256 to each value. Only 256 keys, and gradients stay smooth, merely “wrapped around”.
  • Channel permutation — swap red, green and blue: only six possibilities.
  • Single table — the same table for all three channels: greys stay grey.
  • A table that changes at every pixel — this becomes a stream cipher: keyed XOR, which also erases shapes.
  • Substitution then permutation — scramble values and positions: neither shapes nor colours remain.

In CipherChronicle

The workbench asks for a key and outputs an opaque PNG. On its own, the method leaves shapes visible: chained with a pixel or block permutation, it also hides the original colours.

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.