Skip to content

Instantly share code, notes, and snippets.

@lachesis
Created March 10, 2024 21:09
Show Gist options
  • Save lachesis/af6d945b86e16207917fdcf0e9cf213b to your computer and use it in GitHub Desktop.
Save lachesis/af6d945b86e16207917fdcf0e9cf213b to your computer and use it in GitHub Desktop.
Tiny script to generate secure passwords that are easy to type quickly on telephone keypads
#!/usr/bin/env python3
import secrets
import sys
letters = [
'abc',
'def',
'ghi',
'jkl',
'mno',
'pqrs',
'tuv',
'wxyz',
]
def main():
try:
leng = int(sys.argv[1])
except Exception:
leng = 12
try:
num = int(sys.argv[2])
except Exception:
num = 10
assert leng >= 1
for _ in range(num):
# start with any letter
pw = secrets.choice(''.join(letters))
for _ in range(leng-1):
last_char = pw[-1]
# now only generate letters that are not on the same key as the last letter
pw += secrets.choice(''.join(lg for lg in letters if last_char not in lg))
print(pw)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment