EXERCISE 1 — Hashing and the avalanche effect ============================================== Commands: echo "transfer 100 dollars" | sha256sum echo "transfer 900 dollars" | sha256sum Example output: 9e2... (64 hex characters) <- for "100 dollars" 41a... (64 hex characters) <- for "900 dollars" (openssl equivalent, if sha256sum isn't present): echo "transfer 100 dollars" | openssl dgst -sha256 echo "transfer 900 dollars" | openssl dgst -sha256 WHAT YOU OBSERVE: - Both digests are EXACTLY 64 hex characters (256 bits) — the output size is fixed regardless of input length. Hash a 1-line string or a 1 GB file: still 64 hex chars. - Changing just "1" -> "9" produces a COMPLETELY different digest, with no resemblance to the first. That is the AVALANCHE EFFECT: a one-bit input change flips, on average, half the output bits. WHY THIS MATTERS FOR INTEGRITY: - If you know the expected digest of some data, you can re-hash what you actually received and compare. Even the tiniest alteration (one digit in a payment amount) yields a totally different digest, so tampering is impossible to hide by making a "small, similar" change. - This is the basis of integrity checking — but remember (Chapter 2 warning): because the hash function is public and keyless, an attacker who changes the data can also recompute a matching digest. A bare hash only protects integrity if the digest itself reaches you untampered. Binding integrity to a sender needs a key -> a MAC. NOTE: piping `echo` includes a trailing newline in the input, so your exact digits will differ from any reference — what matters is the two properties (fixed length, total change), not the specific hex value.