Compare commits

..

3 Commits

2 changed files with 40 additions and 20 deletions

View File

@ -1,15 +1,31 @@
#!/usr/bin/env python #!/usr/bin/env python
"""
Takes desired PIN length as an argument and generates a PIN code of that
length.
"""
import secrets import secrets
import sys import sys
try:
wantedCount = int(sys.argv[1])
except IndexError as noarg:
print("Enter a digit as an argument!")
try: def main():
for i in range(int(wantedCount)): """
print(secrets.randbelow(10), end="") This is where the magic happens.
except NameError as noWantedCount: """
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()
print() print()
print()
if __name__ == "__main__":
main()

View File

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