mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-04-09 01:09:05 +05:30
Python: add hash_to_password.py
This commit is contained in:
parent
2517537ee9
commit
271dbe077a
39
python-programming/hash_to_password.py
Normal file
39
python-programming/hash_to_password.py
Normal file
@ -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__)} <file to hash as password>")
|
||||
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"]
|
||||
)
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user