diff --git a/python-programming/hash_to_password.py b/python-programming/hash_to_password.py new file mode 100644 index 0000000..5a7a07a --- /dev/null +++ b/python-programming/hash_to_password.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# hash_to_password.py +# +# Author: Intel A80486DX2-66 +# License: Creative Commons Zero 1.0 Universal or Unlicense +# SPDX-License-Identifier: CC0-1.0 OR Unlicense + +from hashlib import sha3_512 + +divide_chunks = lambda x, n: [x[i:i + n] for i in range(0, len(x), n)] + +hash_file = lambda file_path: sha3_512(open(file_path, "rb").read()).hexdigest() + +hash_to_password = lambda hash_string, start_from, end_before: ''.join( + [chr((int(''.join(byte), 16) % (end_before - start_from)) + start_from) + for byte in divide_chunks(hash_string, 2)] +) + +if __name__ == "__main__": + from os.path import basename + from sys import argv + + if len(argv) < 2: + print(f"Usage: {basename(__file__)} ") + raise SystemExit + + ASCII_RANGE = { + "start_from": 0x21, + "end_before": 0x7F + } + + print( + hash_to_password( + hash_file(argv[1]), + ASCII_RANGE["start_from"], + ASCII_RANGE["end_before"] + ) + )