Python Challenge - Level 21
- Link: Hidden inside Level 20's ZIP archive (
package.pack)
Problem
Inside level21.zip, extracted using password redavni, is a file named package.pack and a readme.txt that gives clues about looking backwards and peeling layers.
Inspecting package.pack reveals layers of nested compression formats (zlib, bzip2, and reversed byte streams).
Solution
Inspect the magic bytes of each layer:
x\x9c: zlib compressed stream → decompress with zlibBZh: bzip2 compressed stream → decompress with bz2\x9cx(ends with): reversed zlib stream → reverse bytes (data[::-1])hZB(ends with): reversed bzip2 stream → reverse bytes
Tracking the operation types generates a log:
- When applying zlib: print space
' ' - When applying bzip2: print
'#' - When reversing: print a newline
'\n'
The resulting ASCII log spells out the word copper.
Python
import bz2
import zlib
with open("package.pack", "rb") as f:
data = f.read()
log = []
while True:
if data.startswith(b"x\x9c"):
data = zlib.decompress(data)
log.append(" ")
elif data.startswith(b"BZh"):
data = bz2.decompress(data)
log.append("#")
elif data.endswith(b"\x9cx") or data.endswith(b"hZB"):
data = data[::-1]
log.append("\n")
else:
break
print("Peeling log (ASCII art):")
print("".join(log))
print("\nFinal unpacked message:")
print(data[::-1].decode(errors="ignore"))
# "look at your logs"
The printed ASCII art reveals:
### ### ######## ######## ########## ########
####### ####### ######### ######### ######### #########
## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ##
## ## ## ######### ######### ######## #########
## ## ## ######## ######## ######## ########
## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ##
####### ####### ## ## ######### ## ##
### ### ## ## ########## ## ##
Go
package main
import (
"bytes"
"compress/bzip2"
"compress/zlib"
"fmt"
"io"
"os"
"strings"
)
func decompressZlib(data []byte) ([]byte, error) {
r, err := zlib.NewReader(bytes.NewReader(data))
if err != nil {
return nil, err
}
defer r.Close()
return io.ReadAll(r)
}
func decompressBzip2(data []byte) ([]byte, error) {
r := bzip2.NewReader(bytes.NewReader(data))
return io.ReadAll(r)
}
func reverseBytes(data []byte) []byte {
out := make([]byte, len(data))
for i, b := range data {
out[len(data)-1-i] = b
}
return out
}
func main() {
data, err := os.ReadFile("package.pack")
if err != nil {
panic(err)
}
var log strings.Builder
for {
n := len(data)
if n >= 2 && data[0] == 0x78 && data[1] == 0x9c {
data, err = decompressZlib(data)
if err != nil {
break
}
log.WriteByte(' ')
} else if n >= 3 && data[0] == 'B' && data[1] == 'Z' && data[2] == 'h' {
data, err = decompressBzip2(data)
if err != nil {
break
}
log.WriteByte('#')
} else if (n >= 2 && data[n-2] == 0x9c && data[n-1] == 0x78) ||
(n >= 3 && data[n-3] == 'h' && data[n-2] == 'Z' && data[n-1] == 'B') {
data = reverseBytes(data)
log.WriteByte('\n')
} else {
break
}
}
fmt.Println(log.String())
}
Rust
use flate2::read::ZlibDecoder;
use std::fs;
use std::io::Read;
fn decompress_zlib(data: &[u8]) -> Result<Vec<u8>, std::io::Error> {
let mut decoder = ZlibDecoder::new(data);
let mut out = Vec::new();
decoder.read_to_end(&mut out)?;
Ok(out)
}
fn decompress_bz2(data: &[u8]) -> Result<Vec<u8>, std::io::Error> {
let mut decoder = bzip2::read::BzDecoder::new(data);
let mut out = Vec::new();
decoder.read_to_end(&mut out)?;
Ok(out)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut data = fs::read("package.pack")?;
let mut log = String::new();
loop {
let n = data.len();
if data.starts_with(&[0x78, 0x9c]) {
data = decompress_zlib(&data)?;
log.push(' ');
} else if data.starts_with(b"BZh") {
data = decompress_bz2(&data)?;
log.push('#');
} else if data.ends_with(&[0x9c, 0x78]) || data.ends_with(b"hZB") {
data.reverse();
log.push('\n');
} else {
break;
}
}
println!("{log}");
Ok(())
}
Language Comparison
| Feature | Python | Go | Rust |
|---|---|---|---|
| Zlib Decompression | zlib.decompress() stdlib |
compress/zlib stdlib reader |
flate2::read::ZlibDecoder crate |
| Bzip2 Decompression | bz2.decompress() stdlib |
compress/bzip2 stdlib reader |
bzip2::read::BzDecoder crate |
| In-place Byte Reversal | data[::-1] creates a full copied slice |
Manual two-pointer or loop copy | data.reverse() standard library slice method in-place |
| Loop Performance | ~150 ms | ~15 ms | ~8 ms |
Key insight: Rust's data.reverse() mutates the existing vector buffer directly without any heap allocation, unlike Python's [::-1] which creates a fresh copy. Go's standard library includes both zlib and bzip2 decoders without needing external dependencies.
Next Level
The letters spell copper:
Recommended Reading
SponsoredPython Challenge Solutions
Python Challenge Solutions

