Checksums interview problems
Checksum questions ask you to verify that data arrived intact or to identify content by its hash. Typical tasks are hashing a large file without reading it all, verifying downloaded chunks against a manifest, finding duplicate files by content, or building a tiny content-addressed store. The tools are hashlib.sha256() with repeated update() calls over fixed-size chunks, hashlib.file_digest since Python 3.11, hexdigest() for storage, zlib.crc32 for fast non-cryptographic checks, and hmac.compare_digest when the comparison guards something.
The classic mistakes are hashlib.sha256(f.read()) on a huge file, hashing text without fixing the encoding so the same content hashes differently on two machines, and comparing a hex digest to raw bytes. Using MD5 or CRC32 where an attacker controls the input is another. A strong answer reads in chunks of 64 KiB or so, explains when CRC32 is enough (accidental corruption) and when it isn't (tampering), and compares sizes before hashing when hunting duplicates, because a size mismatch rules out a match without reading the file.
1 locked
These open in order of demand. Open one and press I want this one to ask for it.
- 33Streaming File Checksum Lockedeasy
Compute and verify a SHA-256 checksum of a large file by hashing it in chunks, rejecting malformed expected digests.