-
Notifications
You must be signed in to change notification settings - Fork 1
/
keygen.py
executable file
·93 lines (85 loc) · 1.89 KB
/
keygen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""
@file keygen.py
@brief Generates random keystrings.
@author Evan Elias Young
@date 2015-08-12
@date 2022-02-04
@copyright Copyright 2022 Evan Elias Young. All rights reserved.
"""
import argparse
import random
from string import ascii_letters as asciiLetters
key: list[str] = []
chars: list[str] = []
PARSER = argparse.ArgumentParser()
PARSER.add_argument(
"-n", help="Enables the use of numbers in the key", action="store_true"
)
PARSER.add_argument(
"-l", help="Enables the use of letters in the key", action="store_true"
)
PARSER.add_argument(
"-c", help="Enables the use of other characters in the key", action="store_true"
)
PARSER.add_argument(
"-le",
metavar="N",
help="Changes the key's length, default is 16",
type=int,
default=16,
)
PARSER.add_argument(
"-o",
help="Outputs key to the scripts location, rather than to the console",
action="store_true",
)
ARGS = PARSER.parse_args()
if ARGS.n:
chars.extend([str(i) for i in range(10)])
if ARGS.l:
chars.extend(asciiLetters)
if ARGS.c:
chars.extend(
[
"~",
"`",
"!",
"@",
"#",
"$",
"%",
"^",
"&",
"*",
"(",
")",
"-",
"_",
"=",
"+",
"[",
"{",
"]",
"}",
"\\",
";",
":",
"'",
'"',
",",
"<",
".",
">",
"/",
"?",
]
)
if not ARGS.n and not ARGS.l and not ARGS.c:
chars.extend(asciiLetters)
chars.extend([str(i) for i in range(10)])
KEY: str = "".join([random.choice(chars) for i in range(ARGS.le)])
if ARGS.o:
open("key.txt", "w").write(KEY)
else:
print(KEY)