-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquantum_sg.py
88 lines (70 loc) · 2.16 KB
/
quantum_sg.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
import sys
import string
import argparse
import quantum_sg
BLOCK_SIZE = 128
MAX_LENGTH = 1024
def main():
parser = argparse.ArgumentParser(
description="A command line tool that generates a cryptographically "
"secure quantum-level secrets using ANU QRNG."
)
parser.add_argument(
"-n",
"--number",
type=int,
default=1,
help="The number of secrets to be generated (default is 1)",
)
parser.add_argument(
"-l",
"--length",
type=int,
default=24,
help="the length of each generated secret (default is 24)",
)
parser.add_argument(
"-wd",
"--digits",
default=True,
action=argparse.BooleanOptionalAction,
help="include digits in the generated secrets (default is True)",
)
parser.add_argument(
"-wl",
"--lowercase",
default=True,
action=argparse.BooleanOptionalAction,
help="include lowercase characters in the generated secrets (default is True)",
)
parser.add_argument(
"-wu",
"--uppercase",
default=True,
action=argparse.BooleanOptionalAction,
help="include uppercase characters in the generated secrets (default is True)",
)
parser.add_argument(
"-wp",
"--punctuation",
default=False,
action=argparse.BooleanOptionalAction,
help="include punctuation characters in the generated secrets (default is False)",
)
args = parser.parse_args()
if args.length > MAX_LENGTH or args.length <= 0:
sys.stdout.write(f'Length must be a non-negative integer and less than or equal to {MAX_LENGTH} \n')
return
population = ""
if args.digits:
population += string.digits
if args.lowercase:
population += string.ascii_lowercase
if args.uppercase:
population += string.ascii_uppercase
if args.punctuation:
population += string.punctuation
for phrase in quantum_sg.rand(population=population, number=args.number, length=args.length):
sys.stdout.write(phrase + "\n")
if __name__ == "__main__":
main()