Created
November 20, 2017 14:07
-
-
Save collinmutembei/0782a685c3f00aed723d95b4b89c0f6c to your computer and use it in GitHub Desktop.
A simple SHA256 hashing example, written in Python using hashlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Generates ten data files, each 300 MB in size and filled with random data. | |
| [[ ! -d "data/" ]] && mkdir "data/" | |
| for i in {1..10}; do | |
| dd if="/dev/random" of="data/file${i}" bs=1m count=300 | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import hashlib | |
| import sys | |
| def sha256_checksum(filename, block_size=65536): | |
| sha256 = hashlib.sha256() | |
| with open(filename, 'rb') as f: | |
| for block in iter(lambda: f.read(block_size), b''): | |
| sha256.update(block) | |
| return sha256.hexdigest() | |
| def main(): | |
| for f in sys.argv[1:]: | |
| checksum = sha256_checksum(f) | |
| print(f + '\t' + checksum) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment