Skip to content

Instantly share code, notes, and snippets.

@caueb
Last active April 3, 2024 23:57
Show Gist options
  • Save caueb/3a1efe4a70134765c1308a2457507ce9 to your computer and use it in GitHub Desktop.
Save caueb/3a1efe4a70134765c1308a2457507ce9 to your computer and use it in GitHub Desktop.
Python wordlist generator for spray/cracking.
#!/usr/bin/env python3
"""
- Combine 2 different words
- Combine 2 different words and capitalize the first word
- Combine 2 different words and capitalize the second word
- Combine 2 different words and convert both to uppercase (optional)
- Combine 2 different words and mutate into leet speak (optional)
- Combine 2 different words, mutate into leet speak, and convert to uppercase (optional)
- Combine 3 different words
- Combine 3 different words and capitalize the first word
- Combine 3 different words and capitalize the second word
- Combine 3 different words and capitalize the third word
- Combine 3 different words and convert all to uppercase (optional)
- Combine 3 different words and mutate into leet speak (optional)
Notes:
- Words are read from an input file and converted to lowercase before processing.
- Combinations are sorted alphabetically before being printed.
- The script ensures no word is combined with itself in any combination.
- Leet speak transformation is applied based on the --leet command-line argument.
- Uppercase transformation is applied based on the --uppercase command-line argument.
- Minimum length for combinations can be specified using the --min flag.
"""
import sys
import argparse
def read_wordlist(filename):
"""Read words from a wordlist file and convert them to lowercase."""
with open(filename, 'r') as file:
words = [line.strip().lower() for line in file.readlines()]
return words
def to_leet_speak(s):
"""Convert a string to leet speak."""
substitutions = {
'a': '4', 'A': '4',
'e': '3', 'E': '3',
'i': '1', 'I': '1',
'o': '0', 'O': '0',
't': '7', 'T': '7',
'l': '1', 'L': '1',
's': '5', 'S': '5'
}
return ''.join(substitutions.get(c, c) for c in s)
def generate_combinations(words, use_leet=False, use_uppercase=False):
"""Generate all possible combinations of words without repeating the same word."""
combinations = []
for word1 in words:
for word2 in words:
if word1 != word2:
base_combos = [
word1 + word2,
word1.capitalize() + word2,
word1 + word2.capitalize(),
word1.capitalize() + word2.capitalize()
]
if use_uppercase:
base_combos.append((word1 + word2).upper())
combinations.extend(base_combos)
for word1 in words:
for word2 in words:
if word1 != word2:
for word3 in words:
if word3 != word1 and word3 != word2:
base_combos = [
word1 + word2 + word3,
word1.capitalize() + word2 + word3,
word1 + word2.capitalize() + word3,
word1 + word2 + word3.capitalize(),
word1.capitalize() + word2.capitalize() + word3,
word1.capitalize() + word2.capitalize() + word3.capitalize()
]
if use_uppercase:
base_combos.append((word1 + word2 + word3).upper())
combinations.extend(base_combos)
# If --leet is set, create leet speak mutations and append them
if use_leet:
leet_combinations = [to_leet_speak(combo) for combo in combinations]
combinations.extend(leet_combinations) # Append leet speak versions to the original combinations
# Remove any duplicates and sort alphabetically
return sorted(set(combinations))
def main(wordlist_file, use_leet=False, use_uppercase=False, min_length=5):
words = read_wordlist(wordlist_file)
combinations = generate_combinations(words, use_leet, use_uppercase)
# Calculate the number of combinations before filtering
total_combinations_before_filtering = len(combinations)
# Filter out combinations shorter than 5 characters
filtered_combinations = [combo for combo in combinations if len(combo) >= min_length]
# Calculate the number of filtered combinations
total_filtered_combinations = total_combinations_before_filtering - len(filtered_combinations)
# Sort the filtered combinations alphabetically
filtered_combinations.sort()
for combo in filtered_combinations:
print(combo)
# Print summary
print(f"\nFiltered out {total_filtered_combinations} words shorter than {min_length} characters.", file=sys.stderr)
summary_message = f"Generated a total of {len(filtered_combinations)} new words from the {len(words)} provided.\n"
print(summary_message, file=sys.stderr)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate word combinations with optional transformations.")
parser.add_argument('wordlist_file', type=str, help="The file containing words to combine.")
parser.add_argument('--leet', action='store_true', help="Apply leet speak transformations to combinations.")
parser.add_argument('--uppercase', action='store_true', help="Convert combinations to uppercase.")
parser.add_argument('--min', type=int, default=5, help="Specify the minimum length for combinations.")
args = parser.parse_args()
main(args.wordlist_file, use_leet=args.leet, use_uppercase=args.uppercase, min_length=args.min)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment