tooling: android apk puzzle extraction

the android lane repeatedly embedded its graded evidence code in assets/huntress_puzzle.json. we built a narrow apk helper that validates the container, extracts that descriptor, decodes it, and verifies the answer shape.

distinguishing an apk from an arbitrary zip

an apk is zip-based, but a filename ending .apk is not proof. the structural check requires:

the binary manifest begins with an xml chunk header. its type must be 0x0003, the header size must be plausible, and its declared total size must fit in the member. dex is not mandatory because resource-only split apks are valid.

puzzle descriptor

the json object contains codec and data. codec names map to the transforms documented in the decoding engine:

ALIASES = {
    "plain": None,
    "base64": "b64",
    "reverse": "reverse",
    "hex": "hex",
    "rot13": "rot13",
    # ...
}

chains such as base64+reverse or hex|rot13 are split and applied from left to right. the final value must fully match ANS-[0-9A-F]{16}.

if the declared codec does not produce that shape, the helper can invoke the bounded decoding engine with the answer regex as its goal. it reports that fallback rather than silently pretending the descriptor was correct.

raw or already expanded input

the orchestration layer may supply the raw apk, the extracted asset, or both. the helper first looks for an exact asset path among expanded files, then scans raw inputs for a structurally valid apk. this makes parsing independent of how the timed server packaged a set.

scope

we also wrote binary-axml and dex metadata readers for package names, components, exported state, intent filters, deep links, strings, classes, and methods. those details were useful for checking the challenge narrative, but the graded answer across the first three days came from the puzzle asset. the tool keeps those two questions separate: “what does this app expose?” and “where did this challenge place its answer?”

day 4 additions

keyed codecs

day 4's descriptor added a key field and the codec xor: base64-decode the data, then xor each byte with the key. keyed steps are part of the codec chain grammar (xor, add, sub, caesar); a bare keyed step implies the base64 layer, and keys may be integers, decimal or 0x strings, or hex bytes.

when the declared codec or key does not yield ANS-[0-9A-F]{16}, the helper tries every single-byte key for xor, add and subtract over the base64, hex and raw readings of the data, plus the reversed result, before the generic search. the answer shape is the acceptance test, so a wrong key cannot produce a plausible answer.

rc4, vigenere and compressed payloads

the codec grammar now also covers rc4 and vigenere (keyed by the puzzle's key) and zlib, gzip and deflate. byte-level steps (the keyed ones, rc4 and the decompressors) take base64 first unless an earlier step already produced bytes; an explicit base64 step whose output is binary hands the bytes on instead of insisting on text. vigenere shifts letters back by the key letters and leaves digits and punctuation alone, which keeps an ANS- value's hex digits intact. every path still ends in the same answer-shape check.

day 5 additions

the split codec leaves data empty and carries the answer as parts[] plus an order[] index list. an index list is ambiguous: order[i] can be the position of parts[i], or the index of the part to take next. the toolkit builds both strings and keeps the one with the answer shape, preferring the position reading the grader confirmed:

placed = [""] * len(parts)
for part, pos in zip(parts, order, strict=True):
    placed[pos - base] = part                     # position reading
by_sequence = "".join(parts[i - base] for i in order)

base absorbs one-based indices. parts may also be {index, value} objects. split can be one step of a chain: if neither join has the answer shape, the join becomes the data of a smaller puzzle and is decoded with the rest of the codec (split+base64). when nothing matches, the decoder raises and the raw puzzle json is kept for inspection.

day 7 additions

keyed steps on raw text

a keyed byte step (xor, add, sub, and caesar as an alias of add) used to base64-decode its input first, as day 4's xor puzzle required. day 7's caesar shifted the answer text itself, so the declared codec failed and the answer came from the key search. a keyed step now base64-decodes only text that is base64.

codec names from other lanes

warmups encodings have reappeared as puzzle codecs a few days later. binary, decimal, octal, percent (and spellings such as url-encoded, ascii, charcode), morse, atbash, base58, base45, base36, base62, base91, a1z26, html and unicode now map straight onto the decoding registry instead of reaching the answer by search.

day 8 additions

more codec names, list data

the codec name table gained the encodings the warmups lane used on days 7 and 8 (escapes and html references, unicode and css escapes, nato words), so a puzzle that names one decodes through the same registry. data may also be a json array of byte values instead of a string. a decoded answer that was lowercased by a case-folding step is upper-cased before the shape check, since the answer shape is uppercase hex.

day 9 additions

any registry transform is a codec name

a codec name resolves through the alias table, then any transform in the decoding engine's registry, then the same name with its spelling normalised (case, _, -, spaces) and filler words dropped (cipher, encoding, escape, sequence, string, literal and similar), so Caesar_Cipher and json unicode escape both resolve. a rotN codec names the encoding, so it decodes with rot(26-N). a codec may be a json list of names, and ->, => and ; separate chain steps alongside +, |, ,, > and then. the aliases also cover json string literals and code points.

every reading of the data and the key

day 7's rule decided from the characters whether a keyed step's input was base64. that is a guess: a byte shift can turn an answer into pure letters and digits, which also parse as base64. a keyed step now yields one output per byte reading of its input (base64, hex, the raw text) and per reading of the key (the day 4 byte reading first, then digits as text, as hex bytes, as an integer wider than a byte, or a json byte list). the declared chain is walked depth first over all of them and the first output with the answer shape wins. a step that yields no reading is passed over instead of failing the chain: an escape step decodes to a fixed point, so it can already have done the work of a json-literal step named after it.

keys from the known prefix

the keyed search used to try single-byte keys only. for xor, add and subtract, a key of up to four bytes is fixed by the four known prefix bytes ANS-, so the search derives two-, three- and four-byte keys from the first bytes of the data, and from its last bytes for an answer stored reversed:

def _prefix_keys(raw: bytes, op: str) -> list[bytes]:
    n, out = len(raw), []
    for size in range(2, min(len(PREFIX), n) + 1):
        out.append(bytes(_key_byte(op, raw[i], PREFIX[i]) for i in range(size)))
        tail = bytearray(size)
        for j in range(size):
            tail[(n - 1 - j) % size] = _key_byte(op, raw[n - 1 - j], PREFIX[j])
        out.append(bytes(tail))
    return out

_key_byte inverts one operation: have ^ want for xor, the difference mod 256 for add and subtract. longer keys are not fixed by the prefix, so they are never guessed, and every candidate still has to produce the full answer shape.

tolerant answer extraction

a decoded value is the answer when it has the answer shape after quotes and brackets are stripped, after upper-casing, or as the only ANS- string anywhere in a decoded json document. there is no substring search: two candidates, or the shape inside surrounding text, is no answer, and the decoder raises.

asset and field guards

a moved or renamed puzzle asset is found when exactly one member's name matches *puzzle*.json; none or several is an error. the solver entry point reads each requested field's answer format and raises on any field whose format is not the code, so a question about the app itself (a package, a component) never receives the decoded code.

day 10 additions

split, again and changed

day 10 brought day 5's split codec back unchanged, and the decoder answered it. it also learned the changed forms a repeat may take: each fragment encoded on its own (the rest of the chain decodes every fragment, then the decoded fragments are joined), positions that start at 1 or leave gaps (the fragments are sorted by position rather than indexed by it), a parts object instead of a list, and data holding the fragments with a separator. keys for keyed steps are found under more names and as base64, a byte-level layer such as base32 passes raw bytes to the next step instead of text, and rot18 is a codec name.

manifest and network security config

the day-10 apk carried a compiled network security config that the manifest did not reference. hlib.android now reads the manifest's application and component attributes, provider authorities and grants, meta-data, and the network security config:

app fields answer by exact name only, and an unknown or empty one raises.

day 11 additions

url-safe base64 under a keyed step

a keyed step (xor, add, sub) first turns data into bytes, trying each byte reading the toolkit knows. the standard base64 reader is lenient: it drops characters outside its alphabet, so url-safe text with - or _ decodes without an error into the wrong bytes, and the key then turns them into noise. day 11 added a strict url-safe reading to the list, which accepts only the url-safe alphabet and restores the padding itself:

def _b64url(text: str) -> bytes:
    s = re.sub(r"\s", "", text)
    if not re.fullmatch(r"[A-Za-z0-9_-]+=*", s):
        raise ValueError("not url-safe base64")
    return base64.urlsafe_b64decode(s.rstrip("=") + "=" * (-len(s.rstrip("=")) % 4))

the readings are tried in order (base64, url-safe base64, hex), duplicates are dropped, and the answer pattern decides which result is kept.

day 12 additions

app fields from the other lanes

the manifest and network security config tables answer the app fields they name. a field they do not name used to crash the set even when another lane already parsed the same bytes. android.answers now hands such a name to cross-lane field resolution, skipping the mobile readers it just tried:

for f in fields:
    name = ids.parse(f).field
    out[f] = values.get(name, "")
    if out[f]:
        continue
    try:
        got = crosslane.resolve(name, apk, "app.apk", skip="mobile")
    except KeyError as e:
        misses.append(str(e.args[0]))
        continue
    out[f] = got if isinstance(got, str) else ",".join(got)

the resolver matches the exact field name only, never a similar one. a name with a format word in front (dotnet-..., elf-...) is read from the apk itself when it is that format, or from its one member of that format. a name no reader answers still crashes, and the error now lists the closest readers in every lane.

two more codec names

a puzzle codec can name any transform in the decoding engine, so day 12's two additions there are codecs here as well: inverted case, which only reads text whose uppercase letters outnumber its lowercase ones, and a keyless rail fence, which returns one reading per rail count from 2 to 8 and refuses text of eight or more letters whose letter frequencies are not english.

day 13 additions

aes codecs

day 13's prompt described an app that wraps its data with a key it controls itself. the codec table now reads aes: a codec name with a mode (an aes gcm mode or aes-256-cbc) runs that mode, a bare aes runs gcm, cbc, ctr and ecb. the key comes from the puzzle's key fields (key, aes_key, wrapping_key, secret, password and others), as given when it has an aes size, else derived from it as a passphrase (sha-256, its first 16 bytes, md5). the iv or nonce comes from an iv field, else from the head of the data, and a gcm tag may trail the ciphertext:

def _aes_cases(mode, raw, ivs):
    given = [(v, raw) for v in ivs]
    if mode == "ecb":
        return [(b"", raw)]
    if mode == "cbc":
        return [*given, (raw[:16], raw[16:]), (bytes(16), raw)]
    if mode == "ctr":
        return [*given, (raw[:16], raw[16:]), (raw[:8], raw[8:]), (raw[:12], raw[12:])]
    tail = [(v, raw[:-16]) for v in ivs]
    heads = [(raw[:12], raw[12:-16]), (raw[:16], raw[16:-16]), (raw[:12], raw[12:])]
    return [*given, *tail, *heads]

every combination is one candidate reading; as with every codec, only a reading of the answer's shape is returned, so a wrong mode or iv layout costs nothing. keystore misuse turned out to need plain base64.

day 14 additions

transpositions, substitutions and a key the app holds

four codecs joined the puzzle decoder: a keyed columnar transposition (the key a word or a digit order), a keyed rail fence, a caesar over the 36 letters and digits, and a substitution whose cipher alphabet (over A-Z, A-Z0-9 or the sixteen hex digits) comes from the puzzle. the columnar reading refills the columns in key order, the short columns last, and reads the grid row by row:

def columnar(text: str, order: list[int]) -> str:
    cols, n = len(order), len(text)
    rows, full = -(-n // cols), n % cols or cols
    pieces, at = {}, 0
    for col in order:
        size = rows if col < full else rows - 1
        pieces[col] = text[at : at + size]
        at += size
    return "".join(
        pieces[c][r] for r in range(rows) for c in range(cols) if r < len(pieces[c])
    )

a keyed codec whose puzzle carries no key now tries the app's own strings (dex, resources and assets), the ones beside a key-like word first; type descriptors, paths and class names are never keys.

day 14's own puzzle named caesar, the arithmetic step every earlier caesar day used: predictable crypto.

day 16 additions

a recorded stand-in. a puzzle codec the alias table does not name runs no steps: the data itself is checked first, then the keyed search and the breadth-first peel take over. when one of those searches answers, it now records the codec name as a missing alias-table row with the reading that worked, and the regression replay fails on it (the table check), so a name found by search once is written into the table rather than searched for every day. native on days 15 and 16 never reached the searches: its data already was the answer (jni boundary).

day 17 additions

one character per index

day 17's puzzle (name collapse) gave data as one string and order as a list exactly as long, under the codec name indexed. it is the split rule with one-character parts: order[i] is the position of data[i]. a puzzle with no parts whose order has as many entries as data has characters is read that way when its codec name is not a known step, and any name for a permutation (indexed, permutation, shuffle, scatter) is one step of a chain, so indexed+base64 decodes the joined text next. both readings of the order are tried and the answer shape picks one.

def indexed(puzzle, data):
    order = puzzle.get("order")
    return "parts" not in puzzle and isinstance(order, list) \
        and len(order) == len(data) > 1

day 18 additions

chacha20, triple des and blowfish beside aes

the aes step (day 14) reads a key as given or derived from a passphrase, an iv or nonce from a field, the data's head or zeros, and a mode from the codec name or every mode. the same shape now reads three more ciphers a puzzle codec could name: chacha20 (also chacha, xchacha20: a 32-byte key or sha-256 of the passphrase; a 12, 8 or 24 byte nonce from nonce / iv, the data's head or zeros), des3 (3des, tripledes, des-ede3; a 16 or 24 byte key or sha-256 cut to 24 or 16, md5; cbc with the iv from a field, the data's first 8 bytes or zeros, then ecb) and blowfish (bf; a 4 to 56 byte key or sha-256 cut to 16 or 32; cbc then ecb). a -cbc / -ecb suffix names one mode. pkcs7 padding comes off at the 8-byte block, and the answer shape decides which reading is kept, as for aes.

def block_cases(step, mode, raw, ivs):            # (iv / nonce, ciphertext)
    if step == "chacha20":
        return [*((v, raw) for v in ivs), (raw[:12], raw[12:]), (raw[:8], raw[8:]),
                (raw[:24], raw[24:]), (bytes(12), raw)]
    if mode == "ecb":
        return [(b"", raw)]
    return [*((v, raw) for v in ivs if len(v) == 8), (raw[:8], raw[8:]), (bytes(8), raw)]

day 20 additions

data that names a member

day 20's puzzle (loaded later) set codec to dynamic and data to the path of a second dex inside the apk. before the codec chain runs, a data string with a member-path shape (a dot, no base64 alphabet shape) is looked up in the package by path or base name; the one ANS- string stored in that member is the code, several are an error, and none sends the member's text through the chain as data.

the normal reader first

the stored-code scan that answers a puzzle the chain cannot read had, once it answered a single, answered every mastery set of the same field, and the sets with older codecs store no code. a set now goes to the codec chain first and to the scan only when the chain raises.

day 21 additions

every manifest and signer scalar by name

day 21 asked a metadata question about an apk (package deal): its package name. the manifest parser had it, but the table of named values other categories read held only the transport and component fields. that table now carries the manifest's own attributes and the first signer, so a field named after any of them is answered wherever it is asked.

values = app_fields(manifest, transport)          # cleartext, nsc, providers ...
values |= manifest_fields(manifest)               # package_name, version_code,
                                                  # version_name, permissions,
                                                  # main_activity, counts
values |= signer_fields(zipfile)                  # signer_sha256, subject, issuer
values |= {"dex_count": ..., "file_count": ...}

the main activity is the activity whose intent filter carries both the MAIN action and the LAUNCHER category; the signer's fingerprint is lowercase hex without separators. a package with no signature block, or no openssl, has no signer fields and every other value stands.

day 23 additions

a dalvik interpreter for computed codes

day 23's timed puzzles named schema v2, codec analysis, and no data (hook line and signal): the answer code is computed by the app's own dex. a codec analysis, or a puzzle with no data and no parts, now goes to a dalvik interpreter built on the existing dex parser.

the interpreter runs methods instruction by instruction with java's semantics (64-bit wraparound, wide values as register pairs, logical and arithmetic shifts with six-bit counts for longs), every opcode except invoke-polymorphic and invoke-custom, class initializers and static field values. the library calls such code makes are implemented in python: strings, StringBuilder, the boxed number classes, Math, Arrays, both base64 apis, MessageDigest, java.util.Random with its exact linear congruential generator, and reflection and class loading over the app's own classes. anything else (a thread, a device service, shared preferences) stops the run with an error that names the call; a million-step cap bounds each candidate (day 23's code took about 81,000).

def answer_codes(app, package=""):
    vm = Vm.of(app, package)
    found = []
    for method, called in vm.answer_methods():   # holders of "ANS-", called first
        vm.reset()
        try:
            out = vm.run(method)
        except ValueError:
            if called:
                raise          # the live path is broken: report it
            continue
        if isinstance(out, str) and ANSWER.fullmatch(out) and out not in found:
            found.append(out)
    return found

candidates are the methods whose code loads the ANS- string, ranked so that a method some other method calls comes before one nothing calls; a crash on a called method is reported rather than skipped.

native pieces under an emulator

the ranked pool's later variants computed part of the value in a native library: a native method whose Java_<class>_<method> export sits in a .so under lib/<abi>/. when the interpreter reaches such a call it finds the export in the x86-64 library's dynamic symbols, maps the library's loadable segments, applies its relative relocations, gives the function a jni environment whose string and array functions are stubs backed by python, and runs it under the unicorn cpu emulator with an instruction cap. the day's function was pure register arithmetic (xor of two constants, a rotate, two multiplies). an arm64-only library, or one that calls outside its stubs, is an error that names the member.

assets, resources and a loaded dex

a regular-pool variant read assets/payload.dex through Context.getAssets().open(...), loaded it with an in-memory dex class loader and invoked its answer method by reflection. the interpreter's context is now the launcher activity: assets (open, openFd, list), raw resources and strings through resources.arsc, the apk's own path, the stream and reader classes such code uses, and a class loader over the bytes it is handed, parsed as one more dex. device state still raises by name.

the dex view in triage

triage on an apk now prints the puzzle, the app's classes and methods, the methods holding ANS- and the disassembly of everything they reach (constants and references resolved), plus native methods with their jni symbols and the libraries' exports, so a computed code can be read without an external decompiler.

day 26 additions

a bundle of split apks is one app

day 26 delivered an .apks bundle, a zip of base.apk and feature.apk (split decision). a split apk has a binary manifest (with a split attribute on the root and hasCode="false" on the application) and no dex; the feature split carried no resources or native libraries either, so the structural check above does not accept it. the toolkit now tells a set's apks apart by content: a zip whose central directory lists AndroidManifest.xml is an android package, one with a dex holds code, and of a bundle's apks the one with code is the app (base.apk when several have code). every other apk is a split, keyed by the device path android would install it under:

def bundle(files):
    apks = {n.rpartition("/")[2]: b for n, b in files.items() if is_apk_zip(b)}
    if not apks:
        return files, {}                    # the members as is
    parts = {n: members(b) for n, b in apks.items()}
    with_code = [n for n in parts if is_apk(apks[n])]
    base = "base.apk" if "base.apk" in with_code else (with_code or sorted(parts))[0]
    return parts[base], {n: m for n, m in parts.items() if n != base}

splits = {f"/data/app/{package}/{name}": m for name, m in other_apks.items()}

a set with one apk is that apk, and a set of extracted members with no apk body is read as the members, so the older puzzle kinds are unaffected.

splitSourceDirs and a ZipFile over a split

the time trial's code read sixteen bytes of an asset that only the feature split carries, the way an app reads a split it does not load as resources: it walks Context.getApplicationInfo().splitSourceDirs, opens each path with java.util.zip.ZipFile, asks for assets/<name> and reads the entry's stream. the interpreter's application-info record now carries splitSourceDirs and splitPublicSourceDirs (the split paths, sorted) beside sourceDir, publicSourceDir and packageName, and a ZipFile constructed on a split's path carries that split's members:

if path in vm.splits:
    return Named("zip", path, vm.splits[path])
if path != vm.apk_path:
    raise ValueError(f"ZipFile({path!r}): only the app's own apk and its splits are read")
return Named("zip", path)                   # the base apk's own members

getEntry, getJarEntry, getInputStream and getSize read from whichever member map the zip object carries. a path that is neither the app nor one of its splits still fails by name.

a split puzzle's missing part

the single's base puzzle was a day-5 split puzzle with one part left empty; the part sat in the feature split's assets/huntress_feature.json as a part and a part_index. in a bundle every apk's members are now in view under the apk's name, and before the join each empty slot is filled from any such json (an index past the list appends; a part the base already has is never overwritten):

filled = list(puzzle["parts"])
for row in feature_rows(files):             # every feature json, sorted
    at = part_index(row)
    if "part" not in row or at is None:
        continue
    while len(filled) <= at:
        filled.append("")
    if filled[at] in ("", None):
        filled[at] = str(row["part"])

a computed-code puzzle in a bundle goes to the interpreter with the whole set, so its splits come along.

a missing record field names its builder

the interpreter stands in for framework calls with python functions, kept in a table keyed by the java method; a call returns a small record (ApplicationInfo is one). every such record now remembers the table key that built it, and a read of a field the record lacks fails with that key, the keys the record has, and the shape an added field would take, instead of only the field's name.

day 28 additions

the packet codec: a frame layout chosen by its checksums

day 28's single named a new codec, packet (protocol reconstruction): hex of one frame, a two-byte magic, a one-byte payload length, the answer code and a one-byte trailer that is the xor of every byte before it. rather than hard-code that layout, the codec searches for it: the magic's width, the header bytes after the magic and where a one- or two-byte length sits among them, the length's byte order, and the trailer's width. a layout counts only if it tiles the bytes exactly with one repeated magic, and among those the layout whose trailers verify most often under one checksum rule wins:

CHECKSUMS = {
    1: (xor8, sum8, neg8),
    2: (sum16be, sum16le),
    4: (crc32le, crc32be),
}

def layouts():                       # the single's layout comes first
    for trailer in (1, 0, 2, 4):
        for magic in (2, 4, 3, 1):
            for head in range(1, 9):
                for width in (1, 2):
                    for at in range(head - width + 1):
                        for order in ("big", "little")[: 1 if width == 1 else 2]:
                            yield magic, head, at, width, order, trailer

the codec also reads a message of several frames, back to back in the data or as a json list, because the question's own words ("preserve nonce and ordering semantics") describe one. frames are put in order by a json sequence field, or by a header field whose values number the frames from any base; a nonce seen before marks a replay and that frame is dropped; frames whose checksum fails are dropped first. the joined payloads are ranked: in sequence order before as given, verified frames before all of them. packet also works as one step of a chain with the other codecs.

an answer-shape scan

the single failed at release because the decoder looked for a chain whose whole output is an answer, and the code was a substring of its first reading. when no chain is found, every one-step reading of the puzzle's data is now scanned for the answer's shape: the text itself, its frames, every decoding transform, the decoded bytes as latin-1 and utf-16, inflated, and keyed by the puzzle's own key. one code answers; several come back as ranked candidates. if the first step finds nothing, a bounded second one follows: the same readings keyed by up to sixty-four of the app's own strings, then every first-step reading read once more, capped at two hundred readings or two seconds.

ANSWER = re.compile(r"ANS-[0-9A-F]{16}")

codes = [m.group(0) for r in one_step(puzzle, data) for m in ANSWER.finditer(r)]
codes = codes or [m.group(0) for r in two_step(puzzle, data, app_strings)
                  for m in ANSWER.finditer(r)]

a framework layer for the dalvik interpreter

the interpreter we wrote for day 23 runs an app's own code and stops at the first framework call it does not emulate. day 28 added the calls a computed-code app is most likely to make next: crc32 and adler32 checksums and inflater streams; java's crypto ciphers (aes in ecb, cbc, ctr and gcm, triple des, blowfish, rc4, chacha20-poly1305), hmacs and pbkdf2; java's collections, with hash maps and sets iterating in java 8 bucket order; BigInteger with java's division and remainder rules; org.json with android's coercions and escaping; and Build as one fixed device, with a clock that advances one millisecond per read. the expected values come from running the same calls on a real jdk. a call still missing fails with its key rather than returning a guess.

day 29 additions

the table codec: a byte table keyed by its index

day 29's single named a new codec, table: twenty bytes of hex and an integer key, each byte of the answer shifted by the key plus three times its index (white box key recovery). the keyed search tried constant keys only. the toolkit now reads table (and sbox, schedule) as a codec step, and inside the keyed search it fits index schedules from the answer prefix as known plaintext: ANS- fixes four plaintext bytes, the first two give the two parameters of k_i = a + b*i (and of k_i = a ^ (b*i)), the next two confirm them, so a renamed variant answers with no key and no name. a named key is also tried as the schedule's first value under every step from 0 to 255.

need = [key_byte(op, raw[i], PREFIX[i]) for i in range(len(PREFIX))]
a, b = need[0], (need[1] - need[0]) % 256
if all(need[i] == (a + b * i) % 256 for i in range(2, len(PREFIX))):
    schedule = bytes((a + b * i) % 256 for i in range(len(raw)))

day 30 additions

the layered codec: reversed bytes under a walking key

day 30's single named a new codec, layered: base64 data and an integer key (layered protections). byte j of the decoded data is xored with the json's key plus j, and the result is the code reversed. the json's key is the walk's real first value (an earlier comment in the toolkit called it a lying key; that was wrong). the keyed search tries every byte reading reversed as well as forwards and read the single on its first run; the table step of day 29 read the stored order only. layered (and layers, layer) now names that step, and the step reads each source reversed too:

def walk_reversed(data: bytes, k0: int) -> bytes:
    plain = bytes(b ^ ((k0 + j) & 255) for j, b in enumerate(data))
    return plain[::-1]

a bounded layer peel

day 29 and day 30 each stacked one layer more than the named steps read. a matrix of 7715 generated puzzles (every valid two-layer stack of 18 layers, 400 of depth three, 400 of depth four, under the true codec name, a wrong one and none, with the true key, a wrong one and none) read 2653 before. the peel searches breadth first over the keyless layers (base64, base64url, hex and base32 read strictly, rot13, rot47, reverse, nibble and pair swaps, bit rotations and not, zlib or gzip behind its header) to depth five. a keyed layer (xor, add or sub; a fixed key, a walk a + b*i or a ^ (b*i), or a 2-4 byte repeating key) at any depth is fitted, never searched: the code's four known bytes are carried up through every tail of up to three keyless encodings, and the key they force is checked on the other known bytes. the json's key is tried first, as given and as the first value of a walk of step ±1 to ±3. a reading only a repeating key gives is weak and waits for a strong one; of two strong ones the one with fewer bit steps beside its key wins, then the shorter walk. the matrix reads 7715 of 7715 with no wrong code, a peel over noise misses in about 0.15 seconds at the median inside a one-second budget, and data nothing reads goes to the dex reader before the error is raised (readable data first, a code the app's dex computes beside it second).

two keyed layers and an unnamed block step

an outer key over a text layer has no known bytes to fit, so it is read as the keys whose undo is a text layer a keyless step consumes (base64, base64url, hex or base32; each walk's valid first values one 256-bit mask), fitted at the outer position over binary data only. the second keyed layer's searches run only under a fitted first key, which keeps the miss path inside its budget. an unnamed block step (aes, triple des or blowfish) is tried under the json's key, cbc with the json's iv or the data's head plus ecb, only with a key and only on a binary surface. the full matrix reads 21577 of 21601 puzzles with no wrong code; the misses are stacks deeper than the fitted tails reach.

an ambiguous stack and the unstripped root

with a bit rotation beside a walking key, both placements can decode: the rotations re-factor around the key (rol6 twice reads as rol5 then rol7), and the wrong placement ranked first. both readings now go out as ranked candidates (AnswerCandidates), the rank's pick first, and the runner tries the other inside the attempt if the first is rejected. the peel also seeded its search with the stripped data, so a stack whose outer layer put a whitespace byte on an edge (about one in eleven per edge byte) lost it; the unstripped bytes are now a second root.

changelog

{generated by a clanker}