Skip to content

Instantly share code, notes, and snippets.

@davidbongcc
Forked from spalladino/hash.py
Created February 11, 2019 07:34
Show Gist options
  • Save davidbongcc/a231c82a38ac05ebc47c60f6156ae11d to your computer and use it in GitHub Desktop.
Save davidbongcc/a231c82a38ac05ebc47c60f6156ae11d to your computer and use it in GitHub Desktop.
Solution for Coursera Cryptography 1 course Week 3 programming assignment
from hashlib import sha256
from sys import argv
with open(argv[1], "rb") as f:
blocks = []
block = f.read(1024)
while block:
blocks.append(block)
block = f.read(1024)
h = sha256(blocks[-1])
for block in reversed(blocks[:-1]):
h = sha256(block + h.digest())
print(h.hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment