Created
July 30, 2019 09:46
-
-
Save viraptor/7e6fba2e76931faa586609cc6ba0b9b1 to your computer and use it in GitHub Desktop.
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 python3 | |
import sys | |
from collections import defaultdict | |
import hashlib | |
def calc_hash(line, num): | |
m = hashlib.sha256() | |
m.update(line.encode('ascii')) | |
m.update(b",") | |
m.update(str(num).encode('ascii')) | |
return m.hexdigest() | |
lines = defaultdict(int) | |
for line in sys.stdin: | |
if not line.strip(): | |
continue | |
lines[line] += 1 | |
h = calc_hash(line, lines[line]) | |
print(f"{line.rstrip()},{h}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment