/
check_hashes.py
36 lines (28 loc) Β· 1.03 KB
/
check_hashes.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
from loguru import logger
import base64
from name_that_hash import hash_info, HashTypeObj
class HashChecker:
"""
Call this with an input to identify hashes
"""
def __init__(self, kwargs, nth):
self.kwargs = kwargs
self.hashinfo_obj = hash_info.HashInformation()
self.nth = nth
self.output = []
def file_input(self, f):
for nr, line in enumerate(f, start=1):
line = str(line).strip()
if not line:
logger.trace(f"Skipped empty line {nr}")
continue
self.single_hash(line)
def single_hash(self, chash: str):
if "base64" in self.kwargs:
logger.trace("decoding as base64")
try:
# b64decode returns Bytes obj
chash = base64.b64decode(chash).decode("utf-8")
except:
logger.trace("Failed to base64 decode")
self.output.append(HashTypeObj.HashType(chash, self.nth, self.hashinfo_obj))