ENDC: str = _color_code(0)
BOLD: str = _color_code(1)
UNDERLINE: str = _color_code(4)
BLACK: str = _color_code(30)
RED: str = _color_code(31)
GREEN: str = _color_code(32)
YELLOW: str = _color_code(33)
BLUE: str = _color_code(34)
MAGENTA: str = _color_code(35)
CYAN: str = _color_code(36)
WHITE: str = _color_code(37)
REDBG: str = _color_code(41)
GREENBG: str = _color_code(42)
YELLOWBG: str = _color_code(43)
BLUEBG: str = _color_code(44)
MAGENTABG: str = _color_code(45)
CYANBG: str = _color_code(46)
WHITEBG: str = _color_code(47)
GREY: str = _color_code(90)
REDGREY: str = _color_code(91)
GREENGREY: str = _color_code(92)
YELLOWGREY: str = _color_code(93)
BLUEGREY: str = _color_code(94)
MAGENTAGREY: str = _color_code(95)
CYANGREY: str = _color_code(96)
WHITEGREY: str = _color_code(97)
GREYBG: str = _color_code(100)
REDGREYBG: str = _color_code(101)
GREENGREYBG: str = _color_code(102)
YELLOWGREYBG: str = _color_code(103)
BLUEGREYBG: str = _color_code(104)
MAGENTAGREYBG: str = _color_code(105)
CYANGREYBG: str = _color_code(106)
WHITEGREYBG: str = _color_code(107)
Colors = _Colors()
Colors = _Colors()
def load_wordlist(file_path):
with open(file_path, 'r') as file:
wordlist = [line.strip() for line in file]
return wordlist
# Load the words directly from the NLTK words corpus
english_words = set(words.words())
def is_dictionary_word(word):
return word.lower() in english_words
def is_similar_word(word):
custom_mappings = {'0': 'o', '1': 'i', '3': 'e', '4': 'a', '5': 's', '7': 't', '8': 'b', '9': 'g'}
for number, letter in custom_mappings.items():
word = word.replace(number, letter)
return is_dictionary_word(word)
def similar_to_dictionary_word(word):
custom_mappings = {'0': 'o', '1': 'i', '3': 'e', '4': 'a', '5': 's', '7': 't', '8': 'b', '9': 'g'}
for number, letter in custom_mappings.items():
word = word.replace(number, letter)
return word if is_dictionary_word(word) else None
file_path = 'names.txt'
words_of_user = load_wordlist(file_path)
words_iteration = cycle(words_of_user)
DONE = 0
words_length = len(words_of_user)
def worker():
global words_length, DONE
while DONE < words_length:
with Lock():
word = next(words_iteration)
if is_dictionary_word(word):
print(
f'{Colors.GREEN}| {word} | is a dictionary word. |{Colors.ENDC}'
)
with open('BetterNames.txt', 'a') as file:
file.write(f"{word} -> {word}\n")
elif is_similar_word(word):
similar_word = similar_to_dictionary_word(word)
print(
f'{Colors.YELLOW}| {word} | is a similar word. to {Colors.GREEN}{similar_word} |{Colors.ENDC}'
)
with open('BetterNames.txt', 'a') as file:
file.write(f"{word} -> {similar_word}\n")
else:
print(
f'{Colors.RED}| {word} | is not a dictionary word. |{Colors.ENDC}'
)
DONE += 1
if __name__ == "__main__":
ask_for_threads = input('How many threads do you want to use >>> ')
print(
f'{Colors.BOLD}| Word | Status |{Colors.ENDC}'
)
threads = []
for _ in range(int(ask_for_threads)):
thread = Thread(target=worker)
thread.daemon = True
thread.start()
threads.append(thread)
for th in threads:
th.join()
input()
import re
from nltk.corpus import words
from itertools import cycle
import time
from threading import Thread, Lock
class Colors:
"""Menu colors"""
@staticmethod
def color_code(code):
"""Static method to format color codes"""
return f'\033[{code}m'
ENDC = color_code(0)
BOLD = color_code(1)
UNDERLINE = color_code(4)
BLACK = color_code(30)
RED = color_code(31)
GREEN = color_code(32)
YELLOW = color_code(33)
BLUE = color_code(34)
MAGENTA = color_code(35)
CYAN = color_code(36)
WHITE = color_code(37)
REDBG = color_code(41)
GREENBG = color_code(42)
YELLOWBG = color_code(43)
BLUEBG = color_code(44)
MAGENTABG = color_code(45)
CYANBG = color_code(46)
WHITEBG = color_code(47)
GREY = color_code(90)
REDGREY = color_code(91)
GREENGREY = color_code(92)
YELLOWGREY = color_code(93)
BLUEGREY = color_code(94)
MAGENTAGREY = color_code(95)
CYANGREY = color_code(96)
WHITEGREY = color_code(97)
GREYBG = color_code(100)
REDGREYBG = color_code(101)
GREENGREYBG = color_code(102)
YELLOWGREYBG = color_code(103)
BLUEGREYBG = color_code(104)
MAGENTAGREYBG = color_code(105)
CYANGREYBG = color_code(106)
WHITEGREYBG = color_code(107)
def load_wordlist(file_path):
"""Load words from a text file."""
with open(file_path, 'r') as file:
return [line.strip() for line in file]
# Load the words directly from the NLTK words corpus
english_words = set(words.words())
def is_dictionary_word(word):
"""Check if a word is in the dictionary."""
return word.lower() in english_words
def similar_to_dictionary_word(word):
"""Check if a word can be mapped to an English word."""
custom_mappings = {'0': 'o', '1': 'i', '3': 'e', '4': 'a', '5': 's', '7': 't', '8': 'b', '9': 'g'}
for number, letter in custom_mappings.items():
word = word.replace(number, letter)
return word if is_dictionary_word(word) else None
def worker(words_iteration, lock, words_length):
"""Thread worker function."""
global DONE
while DONE < words_length:
with lock:
word = next(words_iteration)
if is_dictionary_word(word):
print(f'{Colors.GREEN}| {word} | is a dictionary word. |{Colors.ENDC}')
with open('BetterNames.txt', 'a') as file:
file.write(f"{word} -> {word}\n")
else:
similar_word = similar_to_dictionary_word(word)
if similar_word:
print(f'{Colors.YELLOW}| {word} | is similar to {Colors.GREEN}{similar_word} |{Colors.ENDC}')
with open('BetterNames.txt', 'a') as file:
file.write(f"{word} -> {similar_word}\n")
else:
print(f'{Colors.RED}| {word} | is not a dictionary word. |{Colors.ENDC}')
DONE += 1
if __name__ == "__main__":
file_path = 'names.txt'
words_of_user = load_wordlist(file_path)
words_iteration = cycle(words_of_user)
words_length = len(words_of_user)
DONE = 0
ask_for_threads = input('How many threads do you want to use >>> ')
print(f'{Colors.BOLD}| Word | Status |{Colors.ENDC}')
lock = Lock()
threads = []
for _ in range(int(ask_for_threads)):
thread = Thread(target=worker, args=(words_iteration, lock, words_length))
thread.daemon = True
thread.start()
threads.append(thread)
# Joining threads to ensure they complete their execution.
for thread in threads:
thread.join()
print("Processing complete.")