Skip to content

Instantly share code, notes, and snippets.

@quillaja
Created November 6, 2017 04:10
Show Gist options
  • Save quillaja/135dea061355136d9ba19bf041d3c09e to your computer and use it in GitHub Desktop.
Save quillaja/135dea061355136d9ba19bf041d3c09e to your computer and use it in GitHub Desktop.
Sample creation of base64 strings not as hashes.
import random
import argparse
def get_key(length: int = 8) -> str:
b62_alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$+"
key = random.choices(b62_alphabet, k=length)
return ''.join(key)
def main():
parser = argparse.ArgumentParser(
description='Creates random base64 strings.')
parser.add_argument(
'-l',
action='store',
dest='length',
type=int,
default=8,
help='length of the string(s) to create')
parser.add_argument(
'-n',
action='store',
dest='num',
type=int,
default=1,
help='the number of strings to create')
args = parser.parse_args()
for i in range(args.num):
print(get_key(args.length))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment