Skip to content

Commit 2d39d8c

Browse files
committed
add custom wordlist generator tutorial
1 parent 3a8392a commit 2d39d8c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
5050
- [How to Implement the Caesar Cipher in Python](https://thepythoncode.com/article/implement-caesar-cipher-in-python). ([code](ethical-hacking/caesar-cipher))
5151
- [How to Crack the Caesar Cipher in Python](https://thepythoncode.com/article/how-to-crack-caesar-cipher-in-python). ([code](ethical-hacking/caesar-cipher))
5252
- [How to Lock PDFs in Python](https://thepythoncode.com/article/lock-pdfs-in-python). [(code)](ethical-hacking/pdf-locker)
53+
- [How to Create a Custom Wordlist in Python](https://thepythoncode.com/article/make-a-wordlist-generator-in-python). ([code](ethical-hacking/bruteforce-wordlist-generator))
5354

5455
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
5556
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Create a Custom Wordlist in Python](https://thepythoncode.com/article/make-a-wordlist-generator-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Import the argparse module for handling command line arguments.
2+
# Import the itertools module for generating combinations.
3+
import argparse, itertools
4+
5+
6+
# Define a function to generate a wordlist based on given parameters.
7+
def generate_wordlist(characters, min_length, max_length, output_file):
8+
# Open the output file in write mode.
9+
with open(output_file, 'w') as file:
10+
# Iterate over the range of word lengths from min_length to max_length.
11+
for length in range(min_length, max_length + 1):
12+
# Generate all possible combinations of characters with the given length.
13+
for combination in itertools.product(characters, repeat=length):
14+
# Join the characters to form a word and write it to the file
15+
word = ''.join(combination)
16+
file.write(word + '\n')
17+
18+
19+
# Create an ArgumentParser object for handling command line arguments.
20+
parser = argparse.ArgumentParser(description="Generate a custom wordlist similar to crunch.")
21+
22+
# Define command line arguments.
23+
parser.add_argument("-c", "--characters", type=str, default="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
24+
help="Set of characters to include in the wordlist")
25+
parser.add_argument("-min", "--min_length", type=int, default=4, help="Minimum length of the words")
26+
parser.add_argument("-max", "--max_length", type=int, default=6, help="Maximum length of the words")
27+
parser.add_argument("-o", "--output_file", type=str, default="custom_wordlist.txt", help="Output file name")
28+
29+
# Parse the command line arguments.
30+
args = parser.parse_args()
31+
32+
# Call the generate_wordlist function with the provided arguments.
33+
generate_wordlist(args.characters, args.min_length, args.max_length, args.output_file)
34+
35+
# Print a message indicating the wordlist has been generated and saved.
36+
print(f"[+] Wordlist generated and saved to {args.output_file}")

0 commit comments

Comments
 (0)