-
Notifications
You must be signed in to change notification settings - Fork 0
/
createMask.py
76 lines (68 loc) · 2.19 KB
/
createMask.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
import sys
import itertools
import getopt
def createOutputString(list):
out = ""
for item in list:
out += str(item)
return out
def sortSecond(val):
return val[1]
def main(argv):
try:
opts, args = getopt.getopt(argv, "mo:l:")
except getopt.GetoptError as err:
print("error in argument parsing. Available Arguments: -o -l --increment-min")
print(err)
sys.exit(2)
length = 0
path = "generated.txt"
minSize = 1
for opt, arg in opts:
print(opt+" / "+arg)
if opt == '-o':
path = arg
elif opt == '-l':
if int(arg) > 0:
length = int(arg)
else:
print("Given length is lower than 0. The script is using 1 instead")
elif opt == '-m':
if int(arg) > 0:
minSize = int(arg)
else:
print("Given --increment-min is lower than 0. The script is using 0 instead")
possibleValues = ["?l", "?u", "?d", "?h", "?H", "?s", "?a", "?b"]
priority = {}
priority["?l"] = 26
priority["?u"] = 26
priority["?d"] = 10
priority["?h"] = 16
priority["?H"] = 16
priority["?s"] = 33
priority["?a"] = priority["?l"] + priority["?u"] + priority["?d"] + priority["?s"]
priority["?b"] = 255
erg = []
print(str(range(minSize, length+1)))
for i in range(minSize, length+1):
if erg == []:
erg = list(itertools.combinations_with_replacement(possibleValues, i))
else:
zerg = list(itertools.combinations_with_replacement(possibleValues, i))
erg = erg + zerg
print(str(len(zerg)))
combinedErg = []
for item in erg:
prioSum = 1
for val in item:
prioSum *= priority[val]
combinedErg.append([item, prioSum])
combinedErg.sort(key=sortSecond)
with open(path, 'w') as file_handler:
for item in combinedErg:
#file_handler.write(createOutputString(item[0]) + " " +str(item[1])+"\n")
file_handler.write(createOutputString(item[0])+"\n")
print("%s Masks generated" % len(erg))
if __name__ == "__main__":
print(str(sys.argv))
main(sys.argv[1:])