-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateHash.py
49 lines (36 loc) · 1.5 KB
/
createHash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright: © 2020, error434, All rights reserved
import hashlib
# Names of files
words_file_name = "1MillionPassword.txt" #input file name
hashed_words_file_name = "1MillionPassword_hashed.txt" #output file name
# Variable
hash_type = "md5"
def create_hash_md5_text_file(input_list, output_file_name, hash_type):
input_list = list(map(str.strip, input_list)) # strips away the \n
hashesToExport = []
# loop through the words in the input list
for word in input_list:
if hash_type == "md5":
crypt = hashlib.md5()
elif hash_type == "sha1":
crypt = hashlib.sha1()
crypt.update(bytes(word, encoding='utf-8'))
hashOfWord = crypt.hexdigest()
hashesToExport.append(hashOfWord)
print("Creating hash text file: {} ...".format(output_file_name))
# Creating the output file
with open(output_file_name, 'w') as f:
for hashOfWord in hashesToExport:
f.write("%s\n" % hashOfWord)
print("{} has been successfully created".format(output_file_name))
def get_list_of_words_from_file(filename):
# OPENING FILE
print("Opening file: {}".format(filename))
list_of_words = open(filename, 'r', errors='ignore').readlines()
print("Striping breakline characters from the file: {}.".format(filename))
list_of_words = list(map(str.strip, list_of_words))
return (list_of_words)
# get words from file
words_list = get_list_of_words_from_file(words_file_name)
# create the hash
create_hash_md5_text_file(words_list, hashed_words_file_name, hash_type)