Last active
July 11, 2017 15:13
-
-
Save pcorpet/dd8432ec3bcc2ee8bb26f376c5c73464 to your computer and use it in GitHub Desktop.
Simple Python script to SHA-1 hash each line of a file
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
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