forked from blackploit/hash-identifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
44 lines (29 loc) · 1.2 KB
/
helpers.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
import os
import string
from datetime import datetime
from colorama import Fore, Style
def parse_hash_list(hash_list_file_path: str):
hash_list = []
with open(hash_list_file_path, 'r') as f:
for line in f:
hash_value = line.strip()
if hash_value not in hash_list:
hash_list.append(hash_value)
return hash_list
def make_hash_groups_dir():
now = datetime.now().strftime("%Y%m%d%H%M%S")
hash_groups_dirname = f"hashes-{now}"
os.makedirs(hash_groups_dirname, exist_ok=True)
return hash_groups_dirname
def write_hash_group_file(hash_group_dirname: str, algorithm_hashcat_code: str, hash_values: list) -> None:
with open(os.path.join(hash_group_dirname, f"{algorithm_hashcat_code}.txt"), "a") as hash_group_file:
hash_group_file.writelines(f"{hash_value}\n" for hash_value in hash_values)
def print_to_file(content, output):
if output:
print(content, file=output)
def colored_output(text, color="WHITE"):
color = color.upper()
text = getattr(Fore, color, None) + text + Style.RESET_ALL
return text
def is_hex_str(checked_str: str) -> bool:
return all(item in string.hexdigits for item in checked_str)