<commit_before>#!/usr/bin/env python

"""
PyPass3

Dice Roll Optional, Mostly-Random Word, Number, and Mixed Character 
Password Generator

Mozilla Public License Version 2
https://www.mozilla.org/en-US/MPL/2.0/

Copyright (c) 2017 <NAME> <<EMAIL>>

"""

import logging

from urllib import request
from urllib.error import HTTPError

import utils
import config


# Set up logging configuration
# TODO: set up proper logging app with handler, formatter, etc...
logging.basicConfig(
    # filename='output.log',
    format='%(levelname)s %(message)s',
    level=logging.DEBUG
)


def generate_secret(number_rolls: int = 5, number_dice: int =5,
                    how_many: int = 1, output_type: str = 'words',
                    password_length: int = 20):
    """
    Generate a password or passphrase with either random characters,
    words, or numbers. Optionally, choose number of dice rolls
    for passphrase word selection. See https://www.eff.org/dice.

    \n
    Returns unencrypted passphrase or password (output type).

    \b
    Available arguments:
        how_many: how many passwords do you want
        output_type: words, mixed, numbers
        number_rolls: (optional) how many times you want to roll the dice
        number_dice: (optional) how many dice you want to roll
        password_length: (optional) length of output type
    """

    # TODO: number of rolls = number of words
    # TODO: number of dice determine which word list

    chars = config.CHARACTERS
    factor = 1
    api_max_length = config.ROC_API_MAX_LENGTH
    result = []
    roc = utils.get_roc()

    if output_type == 'words':

        if number_dice == 4:
            word_list = config.WORDLIST_SHORT
            logging.info(
                '[{0}] Using short word list...'.format(utils.get_timestamp()))
        else:
            word_list = config.WORDLIST_LONG
            logging.info(
                '[{0}] Using long word list...'.format(utils.get_timestamp()))

        chunked_list = _prepare_chunks(number_rolls, number_dice)
        result, password_length = _match_numbers_words(word_list, chunked_list)

    elif output_type == 'numbers':
        chars = '1234567890'

        logging.info(
            '[{0}] Output type `numbers` selected...'.format(
                utils.get_timestamp())
        )

    else:
        logging.info(
            '[{0}] Output type `mixed` selected...'.format(
                utils.get_timestamp())
        )

    if output_type != 'words':

        if password_length <= 20:
            result = ''.join(roc.generate_strings(factor * how_many,
                                                  password_length, chars))
        elif password_length > 20:
            result = _concatenate_remainder(roc, chars, password_length,
                                            how_many, api_max_length)
    else:
        result = result

    logging.info('[{0}] Your password is: {1}'.format(
        utils.get_timestamp(), result)
    )

    return result


def _match_numbers_words(wd_list, ch_list):
    """
    Match numbers from dice rolls to word list.
    
    :param wd_list: word list
    :param ch_list: chunked lists of numbers for dice rolls
    :return: passphrase and length
    """

    # Initialize list, dict, and empty passphrase
    password_length = 0
    super_list = []<commit_msg>Refgactor to secret, add char as arg to function.<commit_after>#!/usr/bin/env python

"""
PyPass3

Dice Roll Optional, Mostly-Random Word, Number, and Mixed Character 
Password Generator

Mozilla Public License Version 2
https://www.mozilla.org/en-US/MPL/2.0/

Copyright (c) 2017 <NAME> <<EMAIL>>

"""

import logging

from urllib import request
from urllib.error import HTTPError

import utils
import config


# Set up logging configuration
# TODO: set up proper logging app with handler, formatter, etc...
logging.basicConfig(
    # filename='output.log',
    format='%(levelname)s %(message)s',
    level=logging.DEBUG
)


def generate_secret(number_rolls: int = 5, number_dice: int = 5,
                    how_many: int = 1, output_type: str = 'words',
                    secret_length: int = 20, chars: str = config.CHARACTERS):
    """
    Generate a password or passphrase with either random characters,
    words, or numbers. Optionally, choose number of dice rolls
    for passphrase word selection. See https://www.eff.org/dice.

    \n
    Returns unencrypted passphrase or password (output type).

    \b
    Available arguments:
        how_many: how many passwords do you want
        output_type: words, mixed, numbers
        number_rolls: (optional) how many times you want to roll the dice
        number_dice: (optional) how many dice you want to roll
        password_length: (optional) length of output type
    """

    # TODO: number of rolls = number of words
    # TODO: number of dice determine which word list

    # chars = config.CHARACTERS
    factor = 1
    api_max_length = config.ROC_API_MAX_LENGTH
    result = []
    roc = utils.get_roc()

    if output_type == 'words':

        if number_dice == 4:
            word_list = config.WORDLIST_SHORT
            logging.info(
                '[{0}] Using short word list...'.format(utils.get_timestamp()))
        else:
            word_list = config.WORDLIST_LONG
            logging.info(
                '[{0}] Using long word list...'.format(utils.get_timestamp()))

        chunked_list = _prepare_chunks(number_rolls, number_dice)
        result, secret_length = _match_numbers_words(word_list, chunked_list)

    elif output_type == 'numbers':
        chars = '1234567890'

        logging.info(
            '[{0}] Output type `numbers` selected...'.format(
                utils.get_timestamp())
        )

    else:
        logging.info(
            '[{0}] Output type `mixed` selected...'.format(
                utils.get_timestamp())
        )

    if output_type != 'words':

        if secret_length <= 20:
            result = ''.join(roc.generate_strings(factor * how_many,
                                                  secret_length, chars))
        elif secret_length > 20:
            result = _concatenate_remainder(roc, chars, secret_length,
                                            how_many, api_max_length)
    else:
        result = result

    logging.info('[{0}] Your password is: {1}'.format(
        utils.get_timestamp(), result)
    )

    return result


def _match_numbers_words(wd_list, ch_list):
    """
    Match numbers from dice rolls to word list.
    
    :param wd_list: word list
    :param ch_list: chunked lists of numbers for dice rolls
    :return: passphrase and length
    """

    # Initialize list, dict, and empty passphrase
    password_length = 0
    super_list = []
{'fraction_non_alphanumeric': 0.09602012131972185, 'fraction_numerical': 0.010652463382157125, 'mean_word_length': 2.295953193564115, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4696853', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1890, 'n_words': 589}