Compare commits

..

No commits in common. "bbaf5778effde8197c0ff3336564fcf24b2e9b5a" and "87c57cd34ac1040fc1d2993720b73a0e505534e2" have entirely different histories.

2 changed files with 20 additions and 40 deletions

View File

@ -1,31 +1,15 @@
#!/usr/bin/env python
"""
Takes desired PIN length as an argument and generates a PIN code of that
length.
"""
import secrets
import sys
try:
wantedCount = int(sys.argv[1])
except IndexError as noarg:
print("Enter a digit as an argument!")
def main():
"""
This is where the magic happens.
"""
try:
desired_length = int(sys.argv[1])
except IndexError:
print("Enter a digit as an argument!")
try:
for i in range(int(desired_length)):
print(secrets.randbelow(10), end="")
# We satisfy pylint by having the variable here.
# TODO:make this a while loop?
i += 1
except NameError:
print()
try:
for i in range(int(wantedCount)):
print(secrets.randbelow(10), end="")
except NameError as noWantedCount:
print()
if __name__ == "__main__":
main()
print()

View File

@ -4,7 +4,7 @@ This script asks for a SSID name, counts it and tells whether it's of valid
length
"""
# Request input or assume "test" on empty.
GIVENSSID = str(
givenssid = str(
input(
"Please enter the SSID you are thinking of (preferably 26 chars to fit _nomap): ",
)
@ -13,32 +13,28 @@ GIVENSSID = str(
# Ensure it's UTF-8 and store the size. E.g. åäö are longer than oao
# TODO: make this a function too
GIVENSSIDLEN = len(GIVENSSID.encode("utf8"))
givenssidlen = len(givenssid.encode("utf8"))
# Checking the SSID length is done twice, so thus a function
def checkssidlen(GIVENSSIDLEN):
"""
This function checks that the given string is below 32 characters long and
can thus be used as an SSID.
"""
def checkssidlen(givenssidlen):
# 32 bytes should be the maximum SSID length
if GIVENSSIDLEN <= 32:
print(GIVENSSID, "is", GIVENSSIDLEN, "long and thus valid length")
if givenssidlen <= 32:
print(givenssid, "is", givenssidlen, "long and thus valid length")
else:
print(
GIVENSSID,
givenssid,
"is",
GIVENSSIDLEN,
givenssidlen,
"to long, please select a different SSID",
)
# Checking the SSID without _nomap
checkssidlen(GIVENSSIDLEN)
checkssidlen(givenssidlen)
# TODO: make this a function too
GIVENSSIDLEN = len(GIVENSSID.encode("utf8"))
givenssidlen = len(givenssid.encode("utf8"))
# Continuing with _nomap to ensure it also fits
GIVENSSID = GIVENSSID + "_nomap"
checkssidlen(GIVENSSIDLEN)
givenssid = givenssid + "_nomap"
checkssidlen(givenssidlen)