def save_to_file(self, filename: str, show_progress: bool = True): """ Generate all passwords and save directly to a file. Args: filename: Output file path show_progress: Display progress and estimated time """ start_time = time.time() count = 0 with open(filename, 'w', encoding='utf-8') as f: for password in self.generate(): f.write(password + '\n') count += 1 if show_progress and count % 1_000_000 == 0: elapsed = time.time() - start_time percent = (count / self.total_combinations) * 100 rate = count / elapsed if elapsed > 0 else 0 remaining = (self.total_combinations - count) / rate if rate > 0 else 0 sys.stdout.write( f"\rProgress: percent:.2f% (count:, / self.total_combinations:,) | " f"Speed: rate:,.0f pwd/s | ETA: remaining:.0fs " ) sys.stdout.flush() if show_progress: elapsed = time.time() - start_time print(f"\n✅ Saved count:, passwords to 'filename' in elapsed:.2f seconds.")
# 3. Small demo: 4-digit numeric (10,000 combinations) - safe for testing print("\n=== Demo: 4-digit numeric wordlist (saving to file) ===") demo_gen = PasswordWordlistGenerator(length=4, charset="0123456789") demo_gen.save_to_file("4digit_demo.txt", show_progress=True)
def generate(self) -> Iterator[str]: """Generator yielding each password one by one (memory efficient).""" for combo in itertools.product(self.charset, repeat=self.length): yield ''.join(combo) 8 Digit Password Wordlist
# WARNING: 100 million passwords will take ~10-30GB disk space and hours to generate. # For demo, we'll just show preview. Uncomment the line below only if you have space. # numeric_gen.save_to_file("8digit_numeric.txt", show_progress=True)
gen = PasswordWordlistGenerator(length=8, charset="0123456789") gen.save_to_file("8digit_numeric_full.txt", show_progress=True) But ensure you have and patience. # For demo, we'll just show preview
def preview(self, num: int = 10): """Preview first N passwords.""" print(f"First num passwords (length self.length, charset 'self.charset'):") for i, pwd in enumerate(self.generate()): if i >= num: break print(f" pwd") print(f"Total combinations: self.total_combinations:,") if name == " main ": # 1. Standard 8-digit numeric wordlist (10^8 = 100 million passwords) print("=== 8-Digit Numeric Wordlist ===") numeric_gen = PasswordWordlistGenerator(length=8, charset="0123456789") numeric_gen.preview(10)
# 2. 8-character lowercase alphanumeric (36^8 = ~2.8 trillion) - too large for disk print("\n=== Alphanumeric (lowercase + digits) ===") alnum_gen = PasswordWordlistGenerator(length=8, charset="abcdefghijklmnopqrstuvwxyz0123456789") print(f"Total combinations: alnum_gen.total_combinations:, (too large for practical saving)") def preview(self, num: int = 10): """Preview first
def __init__(self, length: int = 8, charset: Optional[str] = None): """ Initialize the generator. Args: length: Length of each password (default 8) charset: String of characters to use. If None, uses digits 0-9. """ self.length = length self.charset = charset if charset is not None else "0123456789" self.total_combinations = len(self.charset) ** self.length