1
0
Files
2026-05-14 19:56:24 +02:00

35 lines
769 B
Python

#!/bin/python
import hashlib
from pathlib import Path
CONFFILE = Path("config.txt")
INPUT_DIR = Path("input")
OUTPUT_DIR = Path("output")
HASHMODE = "md5"
with open(CONFFILE) as f:
hash_type = f.read().strip()
if hash_type not in ["md5", "sha256"]:
print("Invalid hash type in config")
exit(1)
HASHMODE = hash_type
for file in tuple(INPUT_DIR.iterdir()):
with open(file, "rb") as f:
content = f.read()
if HASHMODE == "md5":
hash = hashlib.md5(content).hexdigest()
elif HASHMODE == "sha256":
hash = hashlib.sha256(content).hexdigest()
else:
hash = ""
dest = OUTPUT_DIR / (file.name + ".md5")
with open(dest, "w") as f:
f.write(hash)