-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexpand_strings.py
More file actions
64 lines (52 loc) · 1.58 KB
/
expand_strings.py
File metadata and controls
64 lines (52 loc) · 1.58 KB
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
def windows(l, size):
w = []
for i in range(len(l) - size + 1):
w.append(l[i:i+size])
return w
f = open("wordlist.txt", 'r', encoding='utf-8', errors='replace')
CHARSET = "0123456789abcdefghijklmnopqrstuvwxyz_-. "
strings = set()
for line in f.readlines():
line = line.strip()
if len(line) == 0:
continue
strings.add(line)
if "_" not in line:
continue
# print(line.encode())
# Collapse double underscores
while "__" in line:
line = line.replace("__", "_")
parts = [x for x in line.split("_") if len(x) > 1]
if len(parts) == 1:
continue
for i in range(2, len(parts)):
for s in windows(parts, i):
strings.add("_".join(s))
split_part = ""
for c in line.lower():
if c not in CHARSET:
if len(split_part) > 1:
strings.add(split_part)
split_part = ""
continue
split_part += c
if len(split_part) != len(line) and len(split_part) > 1:
strings.add(split_part)
out = open("wordlist_expanded.txt", "w", encoding='utf-8', errors='replace')
for line in sorted(strings):
out.write(line + "\n")
out.close()
out = open("wordlist_expanded_purified.txt", "w", encoding='utf-8', errors='replace')
purified = set()
for line in sorted(strings):
line = line.lower()
if all(c in CHARSET for c in line):
# print("Pure line:", line)
purified.add(line)
# out.write(line + "\n")
# else:
# print("Impure line:", line)
for line in sorted(purified):
out.write(line + "\n")
out.close()