#https://xkcd.com/936/ import random #maybe use an nltk corpus instead and filter common words words = ['the', 'and', 'for', 'are', 'but', 'not', 'all', 'any', 'can', 'had', 'was', 'out', 'day', 'get', 'has', 'how', 'new', 'now', 'old', 'see', 'two', 'way', 'who', 'did', 'its', 'let', 'put', 'say', 'too', 'use', 'that', 'with', 'have', 'this', 'will', 'from', 'they', 'know', 'want', 'been', 'good', 'much', 'some', 'time', 'very', 'when', 'come', 'here', 'just', 'like', 'long', 'make', 'many', 'more', 'only', 'over', 'such', 'take', 'than', 'them', 'well', 'were', 'today', 'about', 'after', 'other', 'being', 'first', 'great', 'found', 'people', 'still', 'under', 'while', 'years', 'before', 'large'] #shoulda used import string, whatever allcharsnonpunct = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' lowercase = 'abcdefghijklmnopqrstuvwxyz' uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' numbe = '1234567890' punct = '!@#?' numberofletters = 8 numberofpasswords = 8 wordstogenerate = 2 def xkcdpassword(wordstogenerate, numberofpasswords): for each in range(numberofpasswords): password2 = '' for each1 in range(wordstogenerate): password2 += words[random.randrange(0,len(words))] #if each1 == 0: x = random.randrange(0,4) if x == 0: password2 += punct[random.randrange(0,len(punct))] elif x == 1: password2 += numbe[random.randrange(0,len(numbe))] elif x == 2: password2 += punct[random.randrange(0,len(punct))] password2 += numbe[random.randrange(0,len(numbe))] elif x == 3: password2 += numbe[random.randrange(0,len(numbe))] password2 += punct[random.randrange(0,len(punct))] print password2 xkcdpassword(wordstogenerate, numberofpasswords)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question