Skip to content

Instantly share code, notes, and snippets.

@11Firefox11
Created April 28, 2023 20:25
Show Gist options
  • Save 11Firefox11/52c5661360392627cfdafdae2489d9a2 to your computer and use it in GitHub Desktop.
Save 11Firefox11/52c5661360392627cfdafdae2489d9a2 to your computer and use it in GitHub Desktop.
Generate 31 passcodes
# 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("]")
@11Firefox11
Copy link
Author

This script is part of my blog post: My 31 Days Passcode Based System for My Sunrise Alarm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment