Created
April 28, 2023 20:25
-
-
Save 11Firefox11/52c5661360392627cfdafdae2489d9a2 to your computer and use it in GitHub Desktop.
Generate 31 passcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script is part of my blog post: https://tomoviktor.com/posts/pialarm-passcodes | |
PASSCODES_JSON_PATH = "passcodes.json" | |
from secrets import token_urlsafe as secrets_token_urlsafe | |
from hashlib import sha1 | |
passcodes_file = open(PASSCODES_JSON_PATH, "w") | |
passcodes_file.write("[") | |
hashes_generated = [] | |
for day_num in range(31): | |
passcode_raw = secrets_token_urlsafe(4) | |
while (passcode_hashed:=sha1(passcode_raw.encode()).hexdigest()) in hashes_generated: passcode_raw = secrets_token_urlsafe(4) | |
hashes_generated.append(passcode_hashed) | |
passcodes_file.write(f"\"{passcode_hashed}\"{',' if day_num != 30 else ''}") | |
print(f"{str(day_num+1).zfill(2)} | {passcode_raw}", end="") | |
input() | |
passcodes_file.write("]") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is part of my blog post: My 31 Days Passcode Based System for My Sunrise Alarm.