def export_subset(self, output_path: str, passwords: List[str]): """Export a subset of passwords to a file""" with open(output_path, 'w', encoding='utf-8') as f: for pwd in passwords: f.write(f"{pwd}\n")
def search(self, pattern: str, case_sensitive: bool = False) -> List[str]: """ Search for passwords matching a pattern Args: pattern: Regex pattern to search for case_sensitive: Whether search is case-sensitive Returns: List of matching passwords """ if not self.loaded: self.load() flags = 0 if case_sensitive else re.IGNORECASE regex = re.compile(pattern, flags) return [pwd for pwd in self.wordlist if regex.search(pwd)] wordlist rockyou
# Example with transformer print("\n=== Password Transformer Demo ===") transformer = RockYouTransformer() test_pwd = "password" On Kali Linux: sudo gunzip /usr/share/wordlists/rockyou
def get_statistics(self) -> Dict: """ Analyze wordlist statistics Returns: Dictionary with statistics """ if not self.loaded: self.load() stats = { 'total_passwords': len(self.wordlist), 'unique_passwords': len(set(self.wordlist)), 'duplicates': len(self.wordlist) - len(set(self.wordlist)), 'length_distribution': {}, 'common_patterns': {}, 'character_types': { 'numeric_only': 0, 'alpha_only': 0, 'alphanumeric': 0, 'special_chars': 0 } } # Analyze password lengths lengths = [len(pwd) for pwd in self.wordlist] length_counter = Counter(lengths) stats['length_distribution'] = dict(length_counter.most_common(10)) # Analyze character types for pwd in self.wordlist: if pwd.isdigit(): stats['character_types']['numeric_only'] += 1 elif pwd.isalpha(): stats['character_types']['alpha_only'] += 1 elif pwd.isalnum(): stats['character_types']['alphanumeric'] += 1 elif any(not c.isalnum() for c in pwd): stats['character_types']['special_chars'] += 1 # Find common patterns common_passwords = Counter(self.wordlist).most_common(20) stats['common_patterns'] = dict(common_passwords) return stats case_sensitive: bool = False) ->
def filter_by_length(self, min_len: int = 0, max_len: Optional[int] = None) -> List[str]: """Filter passwords by length""" if not self.loaded: self.load() return [pwd for pwd in self.wordlist if len(pwd) >= min_len and (max_len is None or len(pwd) <= max_len)]
def __init__(self, filepath: Optional[str] = None): """ Initialize the RockYou wordlist manager Args: filepath: Path to rockyou.txt or rockyou.txt.gz file """ self.filepath = self._find_wordlist(filepath) if filepath else self._find_wordlist() self.wordlist = None self.loaded = False def _find_wordlist(self, filepath: Optional[str] = None) -> str: """Find the rockyou wordlist file""" if filepath and os.path.exists(filepath): return filepath for path in self.COMMON_PATHS: expanded_path = os.path.expanduser(path) if os.path.exists(expanded_path): return expanded_path raise FileNotFoundError( "RockYou wordlist not found. Please provide the correct path. " "On Kali Linux: sudo gunzip /usr/share/wordlists/rockyou.txt.gz" )
try: # Initialize the wordlist manager rockyou = RockYouWordlist() # Load first 1000 passwords for demo print("Loading first 1000 passwords...") passwords = rockyou.load(max_passwords=1000) print(f"Loaded {len(passwords)} passwords\n") # Get statistics print("=== Statistics ===") stats = rockyou.get_statistics() print(f"Total passwords: {stats['total_passwords']}") print(f"Unique passwords: {stats['unique_passwords']}") print(f"Duplicates: {stats['duplicates']}") print("\nTop 10 password lengths:") for length, count in stats['length_distribution'].items(): print(f" Length {length}: {count} passwords") print("\nCharacter type distribution:") for char_type, count in stats['character_types'].items(): print(f" {char_type}: {count}") print("\nTop 5 most common passwords:") for pwd, count in list(stats['common_patterns'].items())[:5]: print(f" '{pwd}': {count} times") # Search functionality print("\n=== Search Examples ===") print("Passwords containing '123':") matches = rockyou.search(r'123') for pwd in matches[:10]: print(f" {pwd}") print("\nPasswords with repeating characters:") matches = rockyou.search(r'(.)\1\1') # Three identical chars in a row for pwd in matches[:10]: print(f" {pwd}") # Filter by length print("\n=== Filtering ===") medium_passwords = rockyou.filter_by_length(min_len=8, max_len=12) print(f"Passwords with 8-12 characters: {len(medium_passwords)}") # Password hashing print("\n=== Password Hashing (MD5) ===") hashes = rockyou.get_hash('md5') for pwd, hash_val in list(hashes.items())[:5]: print(f" {pwd} -> {hash_val}") # Find similar passwords print("\n=== Similar Password Search ===") similar = rockyou.find_similar("password123", threshold=2) print(f"Passwords similar to 'password123': {similar[:10]}") except FileNotFoundError as e: print(f"Error: {e}") print("\nTo get the RockYou wordlist:") print("1. On Kali Linux: sudo gunzip /usr/share/wordlists/rockyou.txt.gz") print("2. Or download from: https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt") class RockYouTransformer: """Transform and mutate passwords from rockyou"""