def word_list_tagger2txt(in_list: list = None,
                         fileout='dictionary-tagged.txt'):
    if in_list is None:
        in_list = [
            Wordlist('eff-long').wordlist,
            [word.lower() for word in Wordlist('aspell-en').wordlist]
        ]
    all_words = set(sum(in_list, []))

    with open(fileout, 'w') as f:
        for word, pos in nltk.pos_tag(sorted(all_words)):
            f.write(word)
            f.write('\t')
            f.write(pos)
            f.write('\n')
Beispiel #2
0
    def __init__(self):
        self.desubstitutions = dict()

        with open(database_path('leetspeak.yaml')) as f:
            leetspeak = yaml.safe_load(f)
            for k, v in leetspeak['min'].items():
                for item in v:
                    if item in NOT_CHARS:
                        self.desubstitutions.setdefault(item, set()).add(k)
            for k, v in leetspeak['reverse'].items():
                if k in NOT_CHARS:
                    self.desubstitutions.setdefault(k, set()).add(v)

        with open(database_path('mnemonic.yaml')) as f:
            major_system = yaml.safe_load(f)['major_system']
            for k, v in major_system.items():
                if k in NOT_CHARS:
                    self.desubstitutions.setdefault(k, set()).update(v)

        assert set(NOT_CHARS) - set(self.desubstitutions.keys()) == set(
        ), "Not all not chars are covered"

        dictionaries_to_include = ['aspell-en', 'cracklib-small', 'eff-long']
        self.dictionary = set(
            sum([
                Wordlist(dictionary).wordlist
                for dictionary in dictionaries_to_include
            ], []))

        self.gibberish = Gibberish()
def word_list_tagger2sqlite(in_list: list = None, fileout='SentenceMaker.db'):
    if in_list is None:
        in_list = [
            Wordlist('eff-long').wordlist,
            [word.lower() for word in Wordlist('aspell-en').wordlist]
        ]
    all_words = set(sum(in_list, []))

    with sqlite3.connect(fileout) as conn:
        conn.execute('''CREATE TABLE dictionary
                                ( id INT PRIMARY KEY NOT NULL,
                                  word TEXT NOT NULL,
                                  pos T EXT NOT NULL);''')
        for i, pair in enumerate(nltk.pos_tag(sorted(all_words))):
            word, pos = pair
            conn.execute(
                '''INSERT INTO dictionary (id, word, pos)
                            VALUES (?, ?, ?)''', (i, word, pos))
        conn.commit()
Beispiel #4
0
class GeneratePassword:
    def __init__(self, word_list=None):
        self.conformize = Conformize()
        self.wordlist = Wordlist(word_list=word_list)

    def generate(self, number_of_words=None, conformize=True, weak=False):
        if weak and number_of_words is None:
            number_of_words = 3
        if number_of_words is None:
            number_of_words = 6

        keywords = [
            self.wordlist.get_random_word() for _ in range(number_of_words)
        ]
        if not conformize:
            return keywords
        else:
            return self.conformize.conformize(keywords, weak=weak)
Beispiel #5
0
 def __init__(self, word_list=None):
     self.conformize = Conformize()
     self.wordlist = Wordlist(word_list=word_list)
Beispiel #6
0
from bottle import Bottle, template, TEMPLATE_PATH, request, static_file

from randomsentence.sentence_maker import SentenceMaker
from randomsentence.sentence_tools import SentenceTools

from diceware_utils.wordlist import Wordlist
from diceware_utils.policy import Conformize

word_list = Wordlist()
conformize = Conformize()
sentence_maker = SentenceMaker()
sentence_tools = SentenceTools()

dicewareapp = Bottle()
TEMPLATE_PATH.append('./webdemo/templates')


@dicewareapp.route('/')
def index():
    return template('index.html')


@dicewareapp.post('/randomize_words')
def randomize_words():
    count = int(request.forms.get('count', 6))
    return ' '.join([word_list.get_random_word() for _ in range(count)])


@dicewareapp.post('/generate_password')
def generate_password():
    keywords = request.forms.get('keywords', '')