"""HackThisSite Steganography 1 - reproducible decoder. The BMP is an 8-bit indexed image whose pixel bytes carry the payload: two consecutive 0x00 bytes mark the payload, and inside them every 0x16 stands for bit 0 and every 0x17 for bit 1. Usage: uv run python3 solve.py 1.bmp """ import re import struct import sys
defextract_bits(px): marks = [m.start() for m in re.finditer(b"\x00\x00", px)] iflen(marks) < 2: raise SystemExit("no pair of null bytes found in pixel data") payload = px[marks[0] + 2:marks[1]] return"".join("0"if b == 0x16else"1"for b in payload)
defbits_to_text(bits): # 55 bits: the first character only kept its top 7 bits, so the # trailing 0 of that byte has to be restored before grouping. chars = [bits[:7] + "0"] rest = bits[7:] chars += [rest[i:i + 8] for i inrange(0, len(rest), 8)] return"".join(chr(int(c, 2)) for c in chars)