任何可读和可读的Python密码生成器?

Joh*_*n C 11 python passwords

在Python中生成随机字符串非常简单(例如Python熵显示).但是有没有任何Python项目,它会产生一些有点可读和可读的密码字符串?通过可读性,我的意思是不要将零和O都放在同一个字符串中,等等.我不在乎它是否有最大熵,只是比我可能选择的更好.:)

Gre*_*ins 18

如果你真的只是寻找"比我能弥补的东西"和"可以发音"的东西,那么也许只是random.sample()用来从辅音 - 元音 - 辅音伪音列表中拉出来:

import string
import itertools
import random

initial_consonants = (set(string.ascii_lowercase) - set('aeiou')
                      # remove those easily confused with others
                      - set('qxc')
                      # add some crunchy clusters
                      | set(['bl', 'br', 'cl', 'cr', 'dr', 'fl',
                             'fr', 'gl', 'gr', 'pl', 'pr', 'sk',
                             'sl', 'sm', 'sn', 'sp', 'st', 'str',
                             'sw', 'tr'])
                      )

final_consonants = (set(string.ascii_lowercase) - set('aeiou')
                    # confusable
                    - set('qxcsj')
                    # crunchy clusters
                    | set(['ct', 'ft', 'mp', 'nd', 'ng', 'nk', 'nt',
                           'pt', 'sk', 'sp', 'ss', 'st'])
                    )

vowels = 'aeiou' # we'll keep this simple

# each syllable is consonant-vowel-consonant "pronounceable"
syllables = map(''.join, itertools.product(initial_consonants, 
                                           vowels, 
                                           final_consonants))

# you could trow in number combinations, maybe capitalized versions... 

def gibberish(wordcount, wordlist=syllables):
    return ' '.join(random.sample(wordlist, wordcount))
Run Code Online (Sandbox Code Playgroud)

然后你只需选择适当数量的"单词":

>>> len(syllables)
5320
>>> gibberish(4)
'nong fromp glosk zunt'
>>> gibberish(5)
'samp nuv fog blew grig'
>>> gibberish(10)
'strot fray hag sting skask stim grun prug spaf mond'
Run Code Online (Sandbox Code Playgroud)

我的统计数据有点模糊,但这可能足以用于非NSA目的.请注意,random.sample()无需更换即可运行 我还应该指出,如果恶意方知道您使用的是这种方法,那么它很容易受到字典攻击.一小撮会有所帮助.

更新:对于那些感兴趣的人,可以在https://github.com/greghaskins/gibberish上找到更新和可分享的版本.