Build SHA-256 and HMAC from scratch
Stage 4 of 7v2 · 38560960

One compression round

Compute the boolean functions, rotations, and modular addition for one round.

Build it in your language

The tester treats your program as a black box: any language works. These are just the most convenient ones for this project.

Compression Logic: Choice Function (Ch\text{Ch})

During each of SHA-256's 64 compression rounds, non-linear bitwise functions mix state variables. The Choice function selects bits from yy or zz conditioned on xx.

Mental Model: Choice Definition

eg x \land z)$$ - If bit $k$ of $x$ is 1, bit $k$ of $y$ is selected. - If bit $k$ of $x$ is 0, bit $k$ of $z$ is selected. ### Your Goal in this Stage Read a JSON object from **stdin** with `op: "choice"` and 32-bit unsigned integers `x`, `y`, `z`. Return evaluated Choice in `value`. #### Input Format ```json { "op": "choice", "x": 4294967295, "y": 2863311530, "z": 1431655765 } ``` #### Output Format ```json { "value": 2863311530 } ``` ### Step-by-Step Implementation Guide 1. **Evaluate**: `((x & y) ^ (~x & z)) >>> 0`. 2. **Emit output**: Print JSON with `value`. ### Acceptance Criteria - ✅ Precise 32-bit Choice evaluation. - ✅ Preserves unsigned integer format. ## Output and errors Multiline examples are formatted for readability. Emit compact JSON without optional spaces, with properties in the order shown by the output examples, and a final newline. Keep logs off stdout. Tests compare exact text. Invalid inputs use stderr containing `error`, empty stdout, and exit 1. Valid inputs exit 0. Serialize integer results as JSON integers.