Python Challenge - Level 29

Problem

The page displays an image asking "who is it?". Inspecting the raw HTML source reveals dozens of trailing blank lines after the closing </html> tag. Each line consists of spaces and characters of varying lengths.

Solution

The length of each trailing line encodes a byte value:

  1. Extract all lines after the main HTML body.
  2. Record len(line) for each line.
  3. The resulting byte sequence starts with BZh, indicating a bzip2 compressed payload.
  4. Decompress with bz2 to reveal:

    "Isn't it clear? I am yankeedoodle!"

The answer is yankeedoodle.

Python

import base64
import bz2
import urllib.request

url = "http://www.pythonchallenge.com/pc/ring/guido.html"
auth = "Basic " + base64.b64encode(b"repeat:switch").decode()

req = urllib.request.Request(url, headers={"Authorization": auth})
raw_lines = urllib.request.urlopen(req).read().splitlines()

# Trailing lines start after the main HTML structure (around line 12)
trailing_lines = raw_lines[12:]
byte_stream = bytes(len(line) for line in trailing_lines)

message = bz2.decompress(byte_stream).decode()
print("Hidden message:", message)
# "Isn't it clear? I am yankeedoodle!"

Go

package main

import (
	"bytes"
	"compress/bzip2"
	"encoding/base64"
	"fmt"
	"io"
	"net/http"
)

func main() {
	client := &http.Client{}
	req, _ := http.NewRequest("GET", "http://www.pythonchallenge.com/pc/ring/guido.html", nil)
	auth := base64.StdEncoding.EncodeToString([]byte("repeat:switch"))
	req.Header.Set("Authorization", "Basic "+auth)

	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	lines := bytes.Split(body, []byte("\n"))

	var rawBytes []byte
	for _, l := range lines[12:] {
		rawBytes = append(rawBytes, byte(len(l)))
	}

	bzReader := bzip2.NewReader(bytes.NewReader(rawBytes))
	decompressed, _ := io.ReadAll(bzReader)
	fmt.Printf("Message: %s\n", string(decompressed))
}

Rust

use std::io::Read;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let auth = format!("Basic {}", base64::encode("repeat:switch"));
    let response = ureq::get("http://www.pythonchallenge.com/pc/ring/guido.html")
        .set("Authorization", &auth)
        .call()?
        .into_string()?;

    let lines: Vec<&str> = response.lines().collect();
    let raw_bytes: Vec<u8> = lines[12..].iter().map(|l| l.len() as u8).collect();

    let mut decoder = bzip2::read::BzDecoder::new(&raw_bytes[..]);
    let mut message = String::new();
    decoder.read_to_string(&mut message)?;

    println!("Message: {message}");
    Ok(())
}

Language Comparison

Feature Python Go Rust
Line Splitting read().splitlines() handles CRLF and LF transparently bytes.Split(body, []byte("\n")) or bufio.Scanner .lines() iterator on string slice
Length to Byte Conversion Generator expression bytes(len(l) for l in lines) Append byte(len(l)) to slice .map(|l| l.len() as u8).collect()
Stream Decompression bz2.decompress() compress/bzip2.NewReader() in stdlib bzip2::read::BzDecoder crate

Key insight: Steganography hidden in HTTP whitespace demonstrates how arbitrary payloads can be encoded as line lengths. Go's standard library compress/bzip2 handles the decompression stream with zero external dependencies.

Next Level

Replace guido with yankeedoodle:

http://www.pythonchallenge.com/pc/ring/yankeedoodle.html