back to home

GLASSHEADS, pt. 4 Challenge #1 - Water Trap

The Setup

Help us search the bitplanes to find the 4 secret keys needed to decrypt the flag!

We are given an image, keys.png, and a XOR-encrypted flag.

The planes

The secrets are hidden in the bit planes of keys.png.

A bit plane of a digital discrete signal (such as image or sound) is a set of bits corresponding to a given bit position in each of the binary numbers representing the signal. For example, for 16-bit data representation there are 16 bit planes: the first bit plane contains the set of the most significant bit, and the 16th contains the least significant bit.

I wrote a small Python script to split every colour channel into its 8 bit planes and save them to ./planes/:

#!/usr/bin/env python3
"""Extract all bit planes from keys.png and save them to ./planes/."""

import os
import numpy as np
from PIL import Image

os.makedirs("planes", exist_ok=True)

img = np.array(Image.open("keys.png"))  # shape: (H, W, 3) for RGB, uint8
channels = ["R", "G", "B"]

for ch_idx, ch_name in enumerate(channels):
    channel = img[:, :, ch_idx]
    for bit in range(8):
        # Bit 7 = MSB (bit plane 1), bit 0 = LSB (bit plane 8)
        plane = ((channel >> (7 - bit)) & 1) * 255
        plane_img = Image.fromarray(plane.astype(np.uint8), mode="L")
        plane_img.save(f"planes/{ch_name}_plane_{bit + 1}.png")
        print(f"Saved {ch_name}_plane_{bit + 1}.png")

print("Done")

Looking through the resulting planes, several secrets become readable. XORing all of them together with the encrypted key outputs the flag.