SHA-256 Merkle tree: Difference between revisions

m
m (→‎{{header|Python}}: Reformat to comply with PEP8.)
Line 134:
block = fin.read(block_size)
while block:
# a node is a pair: ( tree-level, hash )
node = (0, hashlib.sha256(block).digest())
stack.append(node)
 
# concatenate adjacent pairs at the same level
while len(stack) >= 2 and stack[-2][0] == stack[-1][0]:
Line 142 ⟶ 144:
l = a[0]
stack[-2:] = [(l+1, hashlib.sha256(a[1] + b[1]).digest())]
 
block = fin.read(block_size)
1,480

edits