Add script and write readme.

This commit is contained in:
2022-08-13 09:11:51 -04:00
parent baf5458f3f
commit 62ee286afd
2 changed files with 69 additions and 1 deletions

View File

@@ -1,3 +1,21 @@
# timelock # timelock
Generate passwords in time. 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: <password>
Confirm password: <password>
100000000 hashes done in 106.24s. Final result:
fe90e6ccb7eb50ddf8237417b2ef8380396285a31d143a880572420206f041c9
```

50
timelock.py Normal file
View File

@@ -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())