Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and Cleanup #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 88 additions & 46 deletions bopscrk/modules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,41 @@ def __init__(self):
parser.add_argument('-w', action="store", metavar='', type=str, dest='words',
help='words to combine comma-separated (will be combined with all words)')

parser.add_argument('-m', '--min', action="store", metavar='', type=int, dest='min',
default=self.DEFAULT_MIN, help='min length for the words to generate (default: {})'.format(self.DEFAULT_MIN))
parser.add_argument(
'-m',
'--min',
action="store",
metavar='',
type=int,
dest='min',
default=self.DEFAULT_MIN,
help=f'min length for the words to generate (default: {self.DEFAULT_MIN})',
)

parser.add_argument('-M', '--max', action="store", metavar='', type=int, dest='max',
default=self.DEFAULT_MAX, help='max length for the words to generate (default: {})'.format(self.DEFAULT_MAX))
parser.add_argument(
'-M',
'--max',
action="store",
metavar='',
type=int,
dest='max',
default=self.DEFAULT_MAX,
help=f'max length for the words to generate (default: {self.DEFAULT_MAX})',
)

parser.add_argument('-c', '--case', action="store_true", help='enable case transformations')

parser.add_argument('-l', '--leet', action="store_true", help='enable leet transformations')

parser.add_argument('-n', action="store", metavar='', type=int, dest='n_words',
default=self.DEFAULT_N_WORDS, help='max amount of words to combine each time '
'(default: {})'.format(self.DEFAULT_N_WORDS))
parser.add_argument(
'-n',
action="store",
metavar='',
type=int,
dest='n_words',
default=self.DEFAULT_N_WORDS,
help=f'max amount of words to combine each time (default: {self.DEFAULT_N_WORDS})',
)
parser.add_argument('-a', '--artists', action="store", metavar='', type=str,
dest='artists', default=False,
help='artists to search song lyrics (comma-separated)')
Expand All @@ -52,13 +74,27 @@ def __init__(self):
# help='exclude all the words included in other wordlists '
# '(several wordlists should be comma-separated)')

parser.add_argument('-o', '--output', action="store", metavar='', type=str,
dest='outfile', default=self.DEFAULT_OUTPUT_FILE,
help='output file to save the wordlist (default: {})'.format(self.DEFAULT_OUTPUT_FILE))
parser.add_argument(
'-o',
'--output',
action="store",
metavar='',
type=str,
dest='outfile',
default=self.DEFAULT_OUTPUT_FILE,
help=f'output file to save the wordlist (default: {self.DEFAULT_OUTPUT_FILE})',
)

parser.add_argument('-C', '--config', action="store", metavar='', type=str,
dest='cfg_file', default=self.DEFAULT_CFG_FILE,
help='specify config file to use (default: {})'.format(self.DEFAULT_CFG_FILE))
parser.add_argument(
'-C',
'--config',
action="store",
metavar='',
type=str,
dest='cfg_file',
default=self.DEFAULT_CFG_FILE,
help=f'specify config file to use (default: {self.DEFAULT_CFG_FILE})',
)

parser.add_argument('--version', action="store_true", help='print version and exit')

Expand All @@ -70,72 +106,78 @@ def __init__(self):

def set_interactive_options(self):
while True:
min_length = input(' {}[?]{} Passwords min length [{}] >>> '.format(color.BLUE, color.END, self.DEFAULT_MIN))
min_length = input(
f' {color.BLUE}[?]{color.END} Passwords min length [{self.DEFAULT_MIN}] >>> '
)
if is_empty(min_length):
self.min_length = self.DEFAULT_MIN; break
else:
try:
self.min_length = int(min_length)
break
except ValueError:
print(' {}[!]{} Min length should be an integer'.format(color.RED, color.END))
print(f' {color.RED}[!]{color.END} Min length should be an integer')
while True:
max_length = input(' {}[?]{} Password\'s max length [{}] >>> '.format(color.BLUE, color.END, self.DEFAULT_MAX))
max_length = input(
f" {color.BLUE}[?]{color.END} Password\'s max length [{self.DEFAULT_MAX}] >>> "
)
if is_empty(max_length):
self.max_length = self.DEFAULT_MAX; break
else:
try:
max_length = int(max_length)
if max_length < self.min_length:
print(' {}[!]{} Max should be greater or equal than min'.format(color.RED, color.END))
print(f' {color.RED}[!]{color.END} Max should be greater or equal than min')
else:
self.max_length = max_length
break
except ValueError:
print(' {}[!]{} Max length should be an integer'.format(color.RED, color.END))
print(f' {color.RED}[!]{color.END} Max length should be an integer')

firstname = input(' {}[?]{} First name >>> '.format(color.BLUE, color.END))
surname = input(' {}[?]{} Surname >>> '.format(color.BLUE, color.END))
lastname = input(' {}[?]{} Last name >>> '.format(color.BLUE, color.END))
firstname = input(f' {color.BLUE}[?]{color.END} First name >>> ')
surname = input(f' {color.BLUE}[?]{color.END} Surname >>> ')
lastname = input(f' {color.BLUE}[?]{color.END} Last name >>> ')

while True:
birth = input(' {}[?]{} Birth date (DD/MM/YYYY) >>> '.format(color.BLUE, color.END))
birth = input(f' {color.BLUE}[?]{color.END} Birth date (DD/MM/YYYY) >>> ')
if not is_empty(birth) and not is_valid_date(birth):
print(' {}[!]{} Birthdate wrong format'.format(color.RED, color.END))
print(f' {color.RED}[!]{color.END} Birthdate wrong format')
else:
break

self.artists = input(' {}[?]{} Artist names to search song lyrics (comma-separated) >>> '.format(color.BLUE, color.END))
if is_empty(self.artists):
self.artists = False
else:
self.artists = self.artists.split(',')

others = input(' {}[?]{} Some other relevant words (comma-separated) >>> '.format(color.BLUE, color.END))

leet = input(' {}[?]{} Do yo want to make leet transforms? [y/n] >>> '.format(color.BLUE, color.END))
case = input(' {}[?]{} Do yo want to make case transforms? [y/n] >>> '.format(color.BLUE, color.END))

if leet.lower() == 'y': self.leet = True
else: self.leet = False
self.artists = input(
f' {color.BLUE}[?]{color.END} Artist names to search song lyrics (comma-separated) >>> '
)
self.artists = False if is_empty(self.artists) else self.artists.split(',')
others = input(
f' {color.BLUE}[?]{color.END} Some other relevant words (comma-separated) >>> '
)

if case.lower() == 'y': self.case = True
else: self.case = False
leet = input(
f' {color.BLUE}[?]{color.END} Do yo want to make leet transforms? [y/n] >>> '
)
case = input(
f' {color.BLUE}[?]{color.END} Do yo want to make case transforms? [y/n] >>> '
)

self.leet = leet.lower() == 'y'
self.case = case.lower() == 'y'
while True:
n_words = input(' {}[?]{} How much words do you want to combine at most [{}] >>> '.format(color.BLUE, color.END, self.DEFAULT_N_WORDS))
n_words = input(
f' {color.BLUE}[?]{color.END} How much words do you want to combine at most [{self.DEFAULT_N_WORDS}] >>> '
)
if is_empty(n_words):
self.n_words = self.DEFAULT_N_WORDS; break
else:
try:
n_words = int(n_words)
if n_words < 1:
print(' {}[!]{} Should be greater or equal than 1'.format(color.RED, color.END))
print(f' {color.RED}[!]{color.END} Should be greater or equal than 1')
else:
self.n_words = n_words
break
except ValueError:
print(' {}[!]{} Should be an integer'.format(color.RED, color.END))
print(f' {color.RED}[!]{color.END} Should be an integer')

# while True:
# exclude = input(' {}[?]{} Exclude words from other wordlists? >>> '.format(color.BLUE, color.END))
Expand All @@ -152,7 +194,9 @@ def set_interactive_options(self):
# self.exclude_wordlists = exclude
# break

self.outfile = input(' {}[?]{} Output file [{}] >>> '.format(color.BLUE, color.END, self.DEFAULT_OUTPUT_FILE))
self.outfile = input(
f' {color.BLUE}[?]{color.END} Output file [{self.DEFAULT_OUTPUT_FILE}] >>> '
)
if is_empty(self.outfile): self.outfile = self.DEFAULT_OUTPUT_FILE

print('') # Print blank line after all questions
Expand All @@ -170,13 +214,11 @@ def set_interactive_options(self):
self.base_wordlist.append(lastname)
if not is_empty(birth):
birth = birth.split('/')
for i in birth:
self.base_wordlist.append(i)
self.base_wordlist.extend(iter(birth))
self.base_wordlist.append((birth[2])[-2:]) # Also add two last digits of the year
if not is_empty(others):
others = others.split(',')
for i in others:
self.base_wordlist.append(i.lower())
self.base_wordlist.extend(i.lower() for i in others)

def set_cli_options(self):
self.base_wordlist = []
Expand Down
18 changes: 7 additions & 11 deletions bopscrk/modules/auxiliars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def is_empty(variable):
"""
Check if a variable (in a type convertible to string) is empty. Returns True or False
"""
empty = False
if len(str(variable)) == 0:
empty = True
return empty
return not str(variable)

def is_valid_date(date_str):
"""
Expand Down Expand Up @@ -49,13 +46,12 @@ def append_wordlist_to_file(filepath, wordlist):

def remove_duplicates_from_file(infile_path, outfile_path="temp.000000000.bopscrk"):
lines_seen = set() # holds lines already seen
outfile = open(outfile_path, "w")
infile = open(infile_path, "r")
for line in infile:
if line not in lines_seen: # not a duplicate
outfile.write(line)
lines_seen.add(line)
outfile.close()
with open(outfile_path, "w") as outfile:
infile = open(infile_path, "r")
for line in infile:
if line not in lines_seen: # not a duplicate
outfile.write(line)
lines_seen.add(line)
Comment on lines 47 to +54

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend sorting the data read here from infile_path before executing the loop, this will remove the need for a set(), reducing the memory footprint of this function. The conditional check for a duplicate is a check if two strings are equal with only accessing those memory locations for comparison, where a set has to verify all values in the set that is does not exist (Many loops even if they are C level loops!).

I use sorted here but if the file is already sorted that can be removed.

def remove_duplicates_from_file(infile_path, outfile_path="temp.000000000.bopscrk"):
    last_line = '' # holds lines already seen
    with open(outfile_path, "w") as outfile:
        infile = open(infile_path, "r")
        for line in sorted(infile):
            if line != last_line:  # not a duplicate
                outfile.write(line)
                last_line = line  

infile.close()
os.remove(infile_path)
os.rename(outfile_path, infile_path)
102 changes: 74 additions & 28 deletions bopscrk/modules/banners.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,84 @@ def banner(name, version, author="r3nt0n"):
name_rand_case = case_transforms(name)
name_rand_case = name_rand_case[randint((len(name_rand_case) - 3), (len(name_rand_case) - 1))]
version = version[:3]
print(' ,----------------------------------------------------, ,------------,');sleep(interval)
print(' | [][][][][] [][][][][] [][][][] [][__] [][][][] | | v{}{}{} |'.format(color.BLUE, version, color.END));sleep(interval)
print(' | | |------------|');sleep(interval)
print(' | [][][][][][][][][][][][][][_] [][][] [][][][] |===| {}{}{} |'.format(color.RED, name_rand_leet, color.END));sleep(interval)
print(' | [_][][][]{}[]{}[][][][]{}[][]{}[][][ | [][][] [][][][] |===| {}{}{}{} |'.format(color.KEY_HIGHL, color.END, color.KEY_HIGHL, color.END, color.BOLD, color.RED, name, color.END));sleep(interval)
print(' | [][_][]{}[]{}[][][][][]{}[]{}[][][][]|| [] [][][][] |===| {}{}{} |'.format(color.KEY_HIGHL, color.END, color.KEY_HIGHL, color.END, color.RED, name_rand_case, color.END));sleep(interval)
print(' | [__][][][]{}[]{}[]{}[]{}[][][][][][__] [][][] [][][]|| | |------------|'.format(color.KEY_HIGHL, color.END, color.KEY_HIGHL, color.END));sleep(interval)
print(' | [__][________________][__] [__][]|| | |{} {} {}|'.format(color.GREEN, author, color.END));sleep(interval)
print(' `----------------------------------------------------´ `------------´\n');sleep(interval)
print(' ,----------------------------------------------------, ,------------,')
sleep(interval)
print(
f' | [][][][][] [][][][][] [][][][] [][__] [][][][] | | v{color.BLUE}{version}{color.END} |'
)
sleep(interval)
print(' | | |------------|')
sleep(interval)
print(
f' | [][][][][][][][][][][][][][_] [][][] [][][][] |===| {color.RED}{name_rand_leet}{color.END} |'
)
sleep(interval)
print(
f' | [_][][][]{color.KEY_HIGHL}[]{color.END}[][][][]{color.KEY_HIGHL}[][]{color.END}[][][ | [][][] [][][][] |===| {color.BOLD}{color.RED}{name}{color.END} |'
)
sleep(interval)
print(
f' | [][_][]{color.KEY_HIGHL}[]{color.END}[][][][][]{color.KEY_HIGHL}[]{color.END}[][][][]|| [] [][][][] |===| {color.RED}{name_rand_case}{color.END} |'
)
sleep(interval)
print(
f' | [__][][][]{color.KEY_HIGHL}[]{color.END}[]{color.KEY_HIGHL}[]{color.END}[][][][][][__] [][][] [][][]|| | |------------|'
)
sleep(interval)
print(
f' | [__][________________][__] [__][]|| | |{color.GREEN} {author} {color.END}|'
)
sleep(interval)
print(' `----------------------------------------------------´ `------------´\n')
sleep(interval)

def help_banner():
print(u' +---------------------------------------------------------------------+');sleep(interval)
print(u' | Fields can be left empty. You can use accentuation in your words. |');sleep(interval)
print(u' | If you enable case transforms, won\'t matter the lower/uppercases |');sleep(interval)
print(u' | in your input. In "others" field (interactive mode), you can write |');sleep(interval)
print(u' | several words comma-separated (e.g.: 2C,Flipper). |');sleep(interval)
print(u' | |');sleep(interval)
print(u' | For advanced usage and documentation: |');sleep(interval)
print(u' | {}https://github.com/r3nt0n/bopscrk{} |'.format(color.ORANGE,color.END));sleep(interval)
print(u' +---------------------------------------------------------------------+\n');sleep(interval)
print(u' +---------------------------------------------------------------------+')
sleep(interval)
print(u' | Fields can be left empty. You can use accentuation in your words. |')
sleep(interval)
print(u' | If you enable case transforms, won\'t matter the lower/uppercases |')
sleep(interval)
print(u' | in your input. In "others" field (interactive mode), you can write |')
sleep(interval)
print(u' | several words comma-separated (e.g.: 2C,Flipper). |')
sleep(interval)
print(u' | |')
sleep(interval)
print(u' | For advanced usage and documentation: |')
sleep(interval)
print(
f' | {color.ORANGE}https://github.com/r3nt0n/bopscrk{color.END} |'
)
sleep(interval)
print(u' +---------------------------------------------------------------------+\n')
sleep(interval)

def bopscrk_banner():
sleep(interval * 4)
print('\n')
print(u'{} ▄▄▄▄ ▒█████ ██▓███ ██████ ▄████▄ ██▀███ ██ ▄█▀'.format(color.ORANGE));sleep(interval)
print(u' ▓█████▄ ▒██▒ ██▒▓██░ ██▒▒██ ▒ ▒██▀ ▀█ ▓██ ▒ ██▒ ██▄█▒ ');sleep(interval)
print(u' ▒██▒ ▄██▒██░ ██▒▓██░ ██▓▒░ ▓██▄ ▒▓█ ▄ ▓██ ░▄█ ▒▓███▄░ ');sleep(interval)
print(u' ▒██░█▀ ▒██ ██░▒██▄█▓▒ ▒ ▒ ██▒▒▓▓▄ ▄██▒▒██▀▀█▄ ▓██ █▄ ');sleep(interval)
print(u' ░▓█ ▀█▓░ ████▓▒░▒██▒ ░ ░▒██████▒▒▒ ▓███▀ ░░██▓ ▒██▒▒██▒ █▄');sleep(interval)
print(u' ░▒▓███▀▒░ ▒░▒░▒░ ▒▓▒░ ░ ░▒ ▒▓▒ ▒ ░░ ░▒ ▒ ░░ ▒▓ ░▒▓░▒ ▒▒ ▓▒');sleep(interval)
print(u' ▒░▒ ░ ░ ▒ ▒░ ░▒ ░ ░ ░▒ ░ ░ ░ ▒ ░▒ ░ ▒░░ ░▒ ▒░');sleep(interval)
print(u' ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░ ░░ ░ ░ ░░ ░');sleep(interval)
print(u' ░ ░ ░ ░ ░ ░ ░ ░ ░');sleep(interval)
print(u' ░ ░ {}'.format(color.END));sleep(interval)
print(
f'{color.ORANGE} ▄▄▄▄ ▒█████ ██▓███ ██████ ▄████▄ ██▀███ ██ ▄█▀'
)
sleep(interval)
print(u' ▓█████▄ ▒██▒ ██▒▓██░ ██▒▒██ ▒ ▒██▀ ▀█ ▓██ ▒ ██▒ ██▄█▒ ')
sleep(interval)
print(u' ▒██▒ ▄██▒██░ ██▒▓██░ ██▓▒░ ▓██▄ ▒▓█ ▄ ▓██ ░▄█ ▒▓███▄░ ')
sleep(interval)
print(u' ▒██░█▀ ▒██ ██░▒██▄█▓▒ ▒ ▒ ██▒▒▓▓▄ ▄██▒▒██▀▀█▄ ▓██ █▄ ')
sleep(interval)
print(u' ░▓█ ▀█▓░ ████▓▒░▒██▒ ░ ░▒██████▒▒▒ ▓███▀ ░░██▓ ▒██▒▒██▒ █▄')
sleep(interval)
print(u' ░▒▓███▀▒░ ▒░▒░▒░ ▒▓▒░ ░ ░▒ ▒▓▒ ▒ ░░ ░▒ ▒ ░░ ▒▓ ░▒▓░▒ ▒▒ ▓▒')
sleep(interval)
print(u' ▒░▒ ░ ░ ▒ ▒░ ░▒ ░ ░ ░▒ ░ ░ ░ ▒ ░▒ ░ ▒░░ ░▒ ▒░')
sleep(interval)
print(u' ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░ ░░ ░ ░ ░░ ░')
sleep(interval)
print(u' ░ ░ ░ ░ ░ ░ ░ ░ ░')
sleep(interval)
print(
f' ░ ░ {color.END}'
)
sleep(interval)
#sleep(interval*2)
Loading