Skip to content

Instantly share code, notes, and snippets.

@pcorpet
Last active July 11, 2017 15:13
Show Gist options
  • Save pcorpet/dd8432ec3bcc2ee8bb26f376c5c73464 to your computer and use it in GitHub Desktop.
Save pcorpet/dd8432ec3bcc2ee8bb26f376c5c73464 to your computer and use it in GitHub Desktop.
Simple Python script to SHA-1 hash each line of a file
import hashlib
import sys
def hash_lines(inputfile, outputfile):
"""Hash all lines of the input file and populate the output."""
count = 0
with open(outputfile, 'wt') as output:
with open(inputfile, 'r') as input_lines:
for line in input_lines:
output.write('%s\n' % hashlib.sha1(line.strip().encode('utf-8')).hexdigest())
count += 1
print('%d lines hashed.' % count)
if __name__ == '__main__':
hash_lines(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment