Build SHA-256 and HMAC from scratch
Stage 2 of 7v2 · 47c2c36d

Blocks and words

Split the padded message into blocks and read big-endian 32-bit words.

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.

32-Bit Message Words Decomposition

SHA-256 operates on 32-bit big-endian unsigned words. Each 64-byte block decomposes into 16 32-bit words (W0,…,W15W_0, \dots, W_{15}).

Mental Model: 4 Bytes per Word

Each word spans 4 bytes (8 hex characters): "0000000100000002":

  • Word 0: "00000001" -> 1
  • Word 1: "00000002" -> 2

Your Goal in this Stage

Read a JSON object from stdin with op: "words" and a hex string. Slice into 32-bit unsigned words.

Input Format

json
{
  "op": "words",
  "hex": "0000000100000002"
}

Output Format

json
{
  "words": [1, 2]
}

Step-by-Step Implementation Guide

  1. Validate length: hex.length must be a multiple of 8.
  2. Parse 8-char slices: Parse each slice as unsigned 32-bit integer (parseInt(slice, 16) >>> 0).
  3. Emit output: Print JSON with words.

Acceptance Criteria

  • ✅ Slices hex into 32-bit big-endian words.
  • ✅ Handles full 32-bit unsigned range without negative values.

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.