Python Challenge - Level 8
Problem

Where is the missing link?
Clicking the fly on the image asks for a username and password with the hint: "inflate". The page source contains two bzip2-compressed, base64-encoded strings:
<!--
un: BZh91AY&SYA\xf8\x8b\x00...
pw: BZh91AY&SYM\xf8\x8b\x00...
-->
inflate = decompress. Decode base64 → decompress bzip2 → read credentials.
Solution
Python
import bz2, urllib.request, re
html = urllib.request.urlopen(
"http://www.pythonchallenge.com/pc/def/integrity.html"
).read().decode()
# Extract the un/pw lines from the HTML comment
un_raw = re.search(r"un: (.+)", html).group(1).encode("raw_unicode_escape")
pw_raw = re.search(r"pw: (.+)", html).group(1).encode("raw_unicode_escape")
username = bz2.decompress(un_raw).decode()
password = bz2.decompress(pw_raw).decode()
print(f"Username: {username}") # huge
print(f"Password: {password}") # file
Why
raw_unicode_escape? The HTML comment contains raw bzip2 bytes embedded as a Python-escaped string literal.encode("raw_unicode_escape")converts the escape sequences back to raw bytes without re-interpreting them as UTF-8.
Go
Go's compress/bzip2 is read-only (decompression only — no writer). That's enough here:
package main
import (
"compress/bzip2"
"fmt"
"io"
"net/http"
"regexp"
"strings"
)
func decompress(raw string) string {
r := bzip2.NewReader(strings.NewReader(raw))
out, _ := io.ReadAll(r)
return string(out)
}
func main() {
resp, _ := http.Get("http://www.pythonchallenge.com/pc/def/integrity.html")
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
reUN := regexp.MustCompile(`un: (.+)`)
rePW := regexp.MustCompile(`pw: (.+)`)
// Extract and decompress
un := decompress(reUN.FindStringSubmatch(string(body))[1])
pw := decompress(rePW.FindStringSubmatch(string(body))[1])
fmt.Println("Username:", un) // huge
fmt.Println("Password:", pw) // file
}
Rust
The bzip2 crate provides BzDecoder:
use bzip2::read::BzDecoder;
use regex::Regex;
use std::io::Read;
fn decompress(raw: &[u8]) -> String {
let mut decoder = BzDecoder::new(raw);
let mut out = String::new();
decoder.read_to_string(&mut out).unwrap();
out
}
fn main() {
let html = reqwest::blocking::get(
"http://www.pythonchallenge.com/pc/def/integrity.html"
).unwrap().text().unwrap();
let re_un = Regex::new(r"un: (.+)").unwrap();
let re_pw = Regex::new(r"pw: (.+)").unwrap();
let un_raw = re_un.captures(&html).unwrap()[1].as_bytes().to_vec();
let pw_raw = re_pw.captures(&html).unwrap()[1].as_bytes().to_vec();
println!("Username: {}", decompress(&un_raw)); // huge
println!("Password: {}", decompress(&pw_raw)); // file
}
Language Comparison
| Feature | Python | Go | Rust |
|---|---|---|---|
| bzip2 decompress | bz2.decompress(data) — stdlib, one call |
compress/bzip2.NewReader() — stdlib, read-only |
bzip2::read::BzDecoder — external crate |
| bzip2 compress | bz2.compress(data) — stdlib |
❌ Not in stdlib — use dsnet/compress |
bzip2::write::BzEncoder — same crate |
| zlib/deflate | zlib.decompress() |
compress/zlib |
flate2 crate |
| Encoding bytes in strings | encode("raw_unicode_escape") — tricky |
[]byte(str) — straightforward |
.as_bytes() — straightforward |
Key insight: Go's stdlib includes bzip2 decompression only — deliberately omitted compression as it's rarely needed in servers. This asymmetry catches Go newcomers off guard. Python and Rust provide both directions. For production Go code needing bzip2 compression, reach for github.com/dsnet/compress/bzip2.
Next Level
http://www.pythonchallenge.com/pc/return/good.html
Username: huge | Password: file

