From 62ee286afdc039b28f21f6a26ede0afb6a58e127 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Sat, 13 Aug 2022 09:11:51 -0400 Subject: [PATCH] Add script and write readme. --- README.md | 20 +++++++++++++++++++- timelock.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 timelock.py diff --git a/README.md b/README.md index 4b1ad37..ccc8b20 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ # timelock -Generate passwords in time. \ No newline at end of file +This program allows you to generate a password by hashing an input phrase a +billion times. You can then use the output as a password. + +After using the password, you throw it away. If you need the password again, you can +recover it via the original phrase and hash count. + +This tool is useful for other apps that lock you out from specific websites and +can be password protected to do so. + +Here is how to use the script: + +``` +python timelock.py +Enter count: 1e8 +Password: +Confirm password: +100000000 hashes done in 106.24s. Final result: +fe90e6ccb7eb50ddf8237417b2ef8380396285a31d143a880572420206f041c9 +``` diff --git a/timelock.py b/timelock.py new file mode 100644 index 0000000..4b2f60c --- /dev/null +++ b/timelock.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import hashlib +import time +import getpass + + +def get_input(): + total_count = 0 + while not total_count: + try: + total_count = int(float(input("Enter count: "))) + except ValueError: + print("Enter a positive integer.") + + seed, seed_check = "a", "b" + while seed != seed_check: + seed = getpass.getpass() + seed_check = getpass.getpass(prompt="Confirm password: ") + if seed != seed_check: + print("Passwords must match.") + return total_count, seed + + +def print_progress(total_count, passed_time, current_count): + projected_time = total_count * passed_time / current_count + progress_time = "[{:.2f} / {:.2f}s".format(passed_time, projected_time) + progress_percent = current_count / total_count * 100 + progress_percent = "- {:.2f}%]".format(progress_percent) + print(progress_time, progress_percent, " ", end='\r') + + +if __name__ == "__main__": + total_count, seed = get_input() + + start_time = time.time() + current_time = start_time + m = hashlib.sha256() + m.update(seed.encode()) + + for current_count in range(total_count): + if time.time() - current_time > 1: + current_time = time.time() + passed_time = current_time - start_time + print_progress(total_count, passed_time, current_count) + m.update(m.digest()) + + time_passed = time.time() - start_time + print(f"{total_count} hashes done in {time_passed:.2f}s. Final result:") + print(m.hexdigest())