wlgen 1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wlgen/__init__.py ADDED
@@ -0,0 +1,54 @@
1
+ def gen_wordlist(charset):
2
+ """Recursively build a wordlist in memory
3
+
4
+ Recursively builds a wordlist in memory, then returns complete list
5
+ which can be written to a file using either stdout or by specifying
6
+ an output file. The wordlist is being built bottom-up by combining
7
+ the current string position's character set with its previous one(s).
8
+
9
+ The input charset is assumed to be unique and sorted.
10
+ Example: {0: '123', 1: 'ABC', 2: '!"§ '}
11
+ """
12
+ subset = {}
13
+ if len(charset) == 1:
14
+ return charset[0]
15
+ else:
16
+ current_pos = charset[0]
17
+ for str_pos in range(1, len(charset)):
18
+ subset[str_pos - 1] = charset[str_pos]
19
+ previous_pos = gen_wordlist(subset)
20
+ wlist = [(i + j) for i in current_pos for j in previous_pos]
21
+ return wlist
22
+
23
+
24
+ def gen_wordlist_iter(charset):
25
+ """Generates a wordlist using itertools.product"""
26
+ from itertools import product
27
+
28
+ charlst = [sorted(set(i)) for i in charset.values()]
29
+ return map("".join, product(*charlst))
30
+
31
+
32
+ def gen_words(charset, positions=None, prev_iter=None):
33
+ """Recursively generate wordlist word for word
34
+
35
+ Recursively generates a wordlist word for word, based on a given
36
+ sets of characters. charset is a dictionary containing character
37
+ sets for each string position of the generated words.
38
+
39
+ The input charset is assumed to be unique and sorted.
40
+ Example: {0: '123', 1: 'ABC', 2: '!"§ '}
41
+ """
42
+ if prev_iter is None:
43
+ positions = [0 for i in charset]
44
+ cur_iter = 0
45
+ else:
46
+ cur_iter = prev_iter + 1
47
+ for idx, _ in enumerate(charset[cur_iter]):
48
+ positions[cur_iter] = idx
49
+ if cur_iter == len(charset) - 1:
50
+ yield "".join(
51
+ [charset[idx][val] for idx, val in enumerate(positions)]
52
+ )
53
+ else:
54
+ yield from gen_words(charset, positions, cur_iter)
@@ -0,0 +1,38 @@
1
+ import filecmp
2
+ import unittest
3
+ import os
4
+ import wlgen
5
+
6
+
7
+ class wlgen_test(unittest.TestCase):
8
+ def setUp(self):
9
+ self.cset = {0: "123", 1: "ABC", 2: ' !"$'}
10
+ if os.name == "nt":
11
+ self.sample = "src/wlgen/tests/files/sample_mixed_dos"
12
+ else:
13
+ self.sample = "src/wlgen/tests/files/sample_mixed_unix"
14
+
15
+ def test_mixed_words(self):
16
+ tfilepath = "src/wlgen/tests/files/tmp"
17
+ with open(tfilepath, "w", encoding="utf-8") as tfile:
18
+ for word in wlgen.gen_words(self.cset):
19
+ tfile.write("%s\n" % word)
20
+ self.assertTrue(filecmp.cmp(tfilepath, self.sample))
21
+
22
+ def test_mixed_list(self):
23
+ tfilepath = "src/wlgen/tests/files/tmp"
24
+ with open(tfilepath, "w", encoding="utf-8") as tfile:
25
+ for word in wlgen.gen_wordlist(self.cset):
26
+ tfile.write("%s\n" % word)
27
+ self.assertTrue(filecmp.cmp(tfilepath, self.sample))
28
+
29
+ def test_mixed_iter(self):
30
+ tfilepath = "src/wlgen/tests/files/tmp"
31
+ with open(tfilepath, "w", encoding="utf-8") as tfile:
32
+ for word in wlgen.gen_wordlist_iter(self.cset):
33
+ tfile.write("%s\n" % word)
34
+ self.assertTrue(filecmp.cmp(tfilepath, self.sample))
35
+
36
+
37
+ if __name__ == "__main__":
38
+ unittest.main()
@@ -0,0 +1,36 @@
1
+ 1A
2
+ 1A!
3
+ 1A"
4
+ 1A$
5
+ 1B
6
+ 1B!
7
+ 1B"
8
+ 1B$
9
+ 1C
10
+ 1C!
11
+ 1C"
12
+ 1C$
13
+ 2A
14
+ 2A!
15
+ 2A"
16
+ 2A$
17
+ 2B
18
+ 2B!
19
+ 2B"
20
+ 2B$
21
+ 2C
22
+ 2C!
23
+ 2C"
24
+ 2C$
25
+ 3A
26
+ 3A!
27
+ 3A"
28
+ 3A$
29
+ 3B
30
+ 3B!
31
+ 3B"
32
+ 3B$
33
+ 3C
34
+ 3C!
35
+ 3C"
36
+ 3C$
@@ -0,0 +1,36 @@
1
+ 1A
2
+ 1A!
3
+ 1A"
4
+ 1A$
5
+ 1B
6
+ 1B!
7
+ 1B"
8
+ 1B$
9
+ 1C
10
+ 1C!
11
+ 1C"
12
+ 1C$
13
+ 2A
14
+ 2A!
15
+ 2A"
16
+ 2A$
17
+ 2B
18
+ 2B!
19
+ 2B"
20
+ 2B$
21
+ 2C
22
+ 2C!
23
+ 2C"
24
+ 2C$
25
+ 3A
26
+ 3A!
27
+ 3A"
28
+ 3A$
29
+ 3B
30
+ 3B!
31
+ 3B"
32
+ 3B$
33
+ 3C
34
+ 3C!
35
+ 3C"
36
+ 3C$
wlgen/tests/files/tmp ADDED
@@ -0,0 +1,36 @@
1
+ 1A
2
+ 1A!
3
+ 1A"
4
+ 1A$
5
+ 1B
6
+ 1B!
7
+ 1B"
8
+ 1B$
9
+ 1C
10
+ 1C!
11
+ 1C"
12
+ 1C$
13
+ 2A
14
+ 2A!
15
+ 2A"
16
+ 2A$
17
+ 2B
18
+ 2B!
19
+ 2B"
20
+ 2B$
21
+ 2C
22
+ 2C!
23
+ 2C"
24
+ 2C$
25
+ 3A
26
+ 3A!
27
+ 3A"
28
+ 3A$
29
+ 3B
30
+ 3B!
31
+ 3B"
32
+ 3B$
33
+ 3C
34
+ 3C!
35
+ 3C"
36
+ 3C$
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: wlgen
3
+ Version: 1.2
4
+ Summary: A recursive wordlist generator written in python
5
+ Author-email: tehw0lf <tehwolf@protonmail.com>
6
+ License-File: LICENSE.txt
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: ruff>=0.8.4
9
+ Requires-Dist: setuptools>=75.6.0
10
+ Description-Content-Type: text/markdown
11
+
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0a096cae2cdf489690eb6e0b4aa80c86)](https://app.codacy.com/app/tehw0lf/wlgen?utm_source=github.com&utm_medium=referral&utm_content=tehw0lf/wlgen&utm_campaign=Badge_Grade_Dashboard)
13
+ [![Build Status](https://travis-ci.com/tehw0lf/wlgen.svg?branch=master)](https://travis-ci.com/tehw0lf/wlgen) [![codecov](https://codecov.io/gh/tehw0lf/wlgen/branch/master/graph/badge.svg)](https://codecov.io/gh/tehw0lf/wlgen)
14
+
15
+ # Description
16
+
17
+ A recursive wordlist generator written in Python.
18
+ For each string position, custom character sets can be defined.
19
+
20
+ # Prerequisites
21
+
22
+ Python 3.x (developed on Python 3.6.4)
23
+
24
+ # Instructions
25
+
26
+ ## Installation
27
+
28
+ To install from GitHub:
29
+
30
+ ```
31
+ git clone https://github.com/tehw0lf/wlgen.git
32
+ cd wlgen
33
+ python setup.py test (optional unit tests to ensure functionality)
34
+ pip install .
35
+ ```
36
+
37
+ To install from PyPI:
38
+
39
+ ```
40
+ pip install wlgen
41
+ ```
42
+
43
+ ## Which function should I use?
44
+
45
+ Currently there are three implementations to generate a wordlist.
46
+ `gen_wordlist` builds the whole list in memory before writing it, `gen_words` is a generator that is memory efficient but slower.
47
+ `gen_wordlist_iter` uses `itertools.product` to generate the wordlist, which is recommended for lists that are too large to be built by `gen_wordlist`.
48
+ Both algorithms calculate the n-ary cartesian product of the input character sets.
@@ -0,0 +1,10 @@
1
+ wlgen/__init__.py,sha256=hK9iJmcG2CZkTyJiD329mbVgHPVUdqa6qerHncs1Vg4,1961
2
+ wlgen/tests/__init__.py,sha256=9DaJ97qqDMsRUuHYwULumACTCtro_xYWUWssEYx752Y,1336
3
+ wlgen/tests/files/sample_mixed_dos,sha256=uLOptT7zup07sisc0TPOjjMpzRnQF7FCIFUdZmISfAc,144
4
+ wlgen/tests/files/sample_mixed_unix,sha256=uLOptT7zup07sisc0TPOjjMpzRnQF7FCIFUdZmISfAc,144
5
+ wlgen/tests/files/tmp,sha256=uLOptT7zup07sisc0TPOjjMpzRnQF7FCIFUdZmISfAc,144
6
+ wlgen-1.2.dist-info/METADATA,sha256=V1gENboXjThvjMT0c0AfK3RHs1fzUISuOgKAll67qQM,1677
7
+ wlgen-1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ wlgen-1.2.dist-info/entry_points.txt,sha256=fmA2JfIuvgdwP8woh4ieNpmfWE-J2iY41O4FXgZYXz8,37
9
+ wlgen-1.2.dist-info/licenses/LICENSE.txt,sha256=PRTS5qlGXIqTHJXHvYvsUaxARnoQmdax_vS37P03snU,1070
10
+ wlgen-1.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ wlgen = wlgen:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Robert Weyres
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.