-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpassgen.py
88 lines (86 loc) · 2.18 KB
/
passgen.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
#passgen#
import sys, random, string
def lowercase():
while True:
try:
char_set = string.ascii_lowercase
result = ''.join(random.sample(char_set*6, 8))
print result
except (KeyboardInterrupt):
exit()
def lowerupper():
while True:
try:
char_set = string.ascii_lowercase + string.ascii_uppercase
result = ''.join(random.sample(char_set*6, 8))
print result
except (KeyboardInterrupt):
exit()
def lowernum():
while True:
try:
char_set = string.ascii_lowercase + string.digits
result = ''.join(random.sample(char_set*6, 8))
print result
except (KeyboardInterrupt):
exit()
def uppernum():
while True:
try:
char_set = string.ascii_uppercase + string.digits
result = ''.join(random.sample(char_set*6, 8))
print result
except (KeyboardInterrupt):
exit()
def loweruppernum():
while True:
try:
char_set = string.ascii_uppercase + string.ascii_lowercase + string.digits
result = ''.join(random.sample(char_set*6, 8))
print result
except (KeyboardInterrupt):
exit()
def uppercase():
while True:
try:
char_set = string.ascii_uppercase
result = ''.join(random.sample(char_set*6, 8))
print result
except (KeyboardInterrupt):
exit()
def arglist():
print 'options: -l lowercase, -lU lower and uppercase, -l1 lower and numerals, -U upper ascii, -U1 upper and numerals, -lU1 lower, upper, and numerals, -C [char] [num] custom character set and length, --help this list'
args = sys.argv[1:]
if args:
for arg in args:
if arg == '-l':
lowercase()
elif arg == '-lU':
lowerupper()
elif arg == '-l1':
lowernum()
elif arg == '-U1':
uppernum()
elif arg == '-lU1':
loweruppernum()
elif arg == '-U':
uppercase()
elif arg == '--help':
arglist()
elif arg == '-C':
while True:
try:
char_set = sys.argv[2]
char_len = sys.argv[3]
result = ''.join([random.choice(char_set) for _ in range(int(char_len))])
print result
except (IndexError):
print(IndexError, "Make sure you've added your character map and length")
exit()
except (ValueError):
print(ValueError, 'ValueError: sample larger than population')
exit()
except (KeyboardInterrupt):
exit()
else:
arglist()