~/ learn/ comp-400/ cards/ Password attacks, hashing, and the three jobs of a salt
1 of 8

Hash one password under three different salts and watch the stored digests diverge — then hash it with no salt and watch two users store byte-identical records. Digests are truncated to 16 hex characters so the output stays readable.

Hash one password under three different salts and watch the stored digests diverge — then hash it with no salt and watch two users store byte-identical records. Digests are truncated to 16 hex characters so the output stays readable.

Answer

import hashlib def stored(password, salt): return hashlib.pbkdf2_hmac('sha256', password.encode(), salt, 100_000).hex()[:16] pw = 'autumn-lantern' for salt in (b'salt:alice', b'salt:bob', b'salt:carol'): print(salt.decode(), '->', stored(pw, salt)) bare = hashlib.sha256(pw.encode()).hexdigest()[:16] print('unsalted alice ->', bare) print('unsalted bob ->', bare) print('same password, same unsalted hash:', bare == hashlib.sha256(pw.encode()).hexdigest()[:16])

Stallings & Brown, Computer Security 5e, ch3 §3.2

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/636906fb-c043-4209-80f0-e03d58306692/flashcard utf-8 LF