Skip to content

Instantly share code, notes, and snippets.

@viraptor
Created July 30, 2019 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viraptor/7e6fba2e76931faa586609cc6ba0b9b1 to your computer and use it in GitHub Desktop.
Save viraptor/7e6fba2e76931faa586609cc6ba0b9b1 to your computer and use it in GitHub Desktop.
#!/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