# Ciphertext reconstruction: a native-cipher control

This is a deterministic teaching experiment, not a new cryptographic result.
Identical plaintext and key are insufficient to reproduce an AES-CBC ciphertext
if the IV changes. Exact ciphertext comparison needs the original encoding inputs.

## Reproduce

Download these four neighboring files into one directory:

- ciphertext-reconstruction.mjs
- ciphertext-reconstruction.test.mjs
- ciphertext-reconstruction.json
- ciphertext-reconstruction.README.md

Use Node.js 22 or later, with its built-in crypto module; no package installation.

```sh
node --test ciphertext-reconstruction.test.mjs
node ciphertext-reconstruction.mjs
```

The generator prints a fresh JSON result. Timestamp and runtime can differ;
the test compares deterministic fields and verifies the generator's SHA-256.
The committed snapshot records the runtime that actually generated it.

## Controls and interpretation

One public NIST AES-128-CBC block supplies a known-answer check.
Three designed comparisons keep the key fixed: change only the IV (mismatch),
replay the original inputs (match), or change plaintext with the original IV
(mismatch). Each ciphertext decrypts to its own input. These are three controls,
not a sample size for a rate or statistical claim. No padding is used.
The IV-prefix framing is our explicit choice, not a claimed paper wire format.

The helpers accept nonempty hexadecimal plaintext comprising complete 16-byte
blocks and an exactly 16-byte hexadecimal IV. Uppercase and lowercase hex denote
the same bytes. Decryption accepts a nonempty Buffer of complete blocks.
Whitespace, invalid characters and a trailing half-byte are rejected before
decoding: Node's Buffer.from(text, "hex") would otherwise silently truncate them.
Regression tests cover this input boundary and a two-block NIST known answer;
they do not add observations to the three designed comparison cases.

The source review prompted a concrete implementation question. Xu, Chang and
Zhou's ASIA CCS 2013 paper, Figure 2 (PDF page 9), compares ciphertext hashes
after prover re-encryption. Section 5, footnote 13, describes a fresh random IV
embedded in the ciphertext. Figure 2's V1 message does not explicitly carry
that IV. An implementation must specify how the prover obtains the original
encoding inputs. An implicit retrieval step may resolve this; we did not
inspect the historical implementation. This is not evidence of an exploitable
vulnerability or a refutation of the paper's security theorem.

## Safety and evidence

Fixed inputs here are public test vectors. Do not replace production random
IV generation with a constant, or reuse an IV for new messages.
The IV need not be secret: NIST permits transmitting it with the ciphertext.
Unpredictability when encrypting a new message is different from making the
original IV available when reconstructing an existing record.
CBC alone does not authenticate data. This harness is not storage software.

- Xu, Chang and Zhou (2013), DOI 10.1145/2484313.2484340:
  https://www.comp.nus.edu.sg/~changec/publications/2013_asiaccs.pdf
- Node.js Buffer documentation, hexadecimal decoding:
  https://nodejs.org/api/buffer.html#buffers-and-character-encodings
- NIST SP 800-38A, sections 5.3 and 6.2, Appendix C and F.2.1:
  https://csrc.nist.gov/pubs/sp/800/38/a/final

The result records the retrieved paper hash and access date. Figure 2 was
visually checked against the downloaded PDF; footnote 13 was text-extracted.
No source PDF is redistributed. No provider was contacted or tested.
