Created
September 10, 2012 23:55
-
-
Save blacktaxi/3694912 to your computer and use it in GitHub Desktop.
Modern password generation with NLTK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 | |
Type "copyright", "credits" or "license()" for more information. | |
>>> import random | |
>>> random.seed() | |
>>> import nltk | |
>>> from nltk.corpus import wordnet as wn | |
>>> nouns, verbs, adjectives, adverbs = [list(wn.all_synsets(pos=POS)) for POS in [wn.NOUN, wn.VERB, wn.ADJ, wn.ADV]] | |
>>> def gen_phrase(*pattern): return [random.choice(i) for i in pattern] | |
>>> def phrase_to_string(phrase): return ' '.join(s.lemmas[0].name for s in phrase) | |
>>> def gen_password(): return phrase_to_string(gen_phrase(adverbs, adjectives, adjectives, nouns)) | |
>>> gen_password() | |
'decidedly Noachian autoplastic bag_lady' | |
>>> gen_password() | |
'ad_val faithful regimented accordance' | |
>>> gen_password() | |
'familiarly votive empty Gadiformes' | |
>>> gen_password() | |
'universally surmountable wiry field_mouse' | |
>>> gen_password() | |
'deadpan bilingual grandiose oxygen_deficit' | |
>>> gen_password() | |
'flip-flap heterozygous unenlightened solitaire' | |
>>> gen_password() | |
'only piquant apart Massawa' | |
>>> gen_password() | |
'continuously forty-two coarse-haired Israel' | |
>>> gen_password() | |
'actually trigger-happy tactful cobia' | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment