Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
119 lines (89 loc) · 3.25 KB

File metadata and controls

executable file
·
119 lines (89 loc) · 3.25 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
"""Password maker, https://xkcd.com/936/"""
import argparse
import random
import re
import string
# --------------------------------------------------
def get_args():
"""Get command-line arguments"""
parser = argparse.ArgumentParser(
description='Password maker',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='+',
help='Input file(s)')
parser.add_argument('-n',
'--num',
metavar='num_passwords',
type=int,
default=3,
help='Number of passwords to generate')
parser.add_argument('-w',
'--num_words',
metavar='num_words',
type=int,
default=4,
help='Number of words to use for password')
parser.add_argument('-m',
'--min_word_len',
metavar='minimum',
type=int,
default=3,
help='Minimum word length')
parser.add_argument('-x',
'--max_word_len',
metavar='maximum',
type=int,
default=6,
help='Maximum word length')
parser.add_argument('-s',
'--seed',
metavar='seed',
type=int,
help='Random seed')
parser.add_argument('-l',
'--l33t',
action='store_true',
help='Obfuscate letters')
return parser.parse_args()
# --------------------------------------------------
def main():
args = get_args()
random.seed(args.seed) # <1>
words = set()
def word_len(word):
return args.min_word_len <= len(word) <= args.max_word_len
for fh in args.file:
for line in fh:
for word in filter(word_len, map(clean, line.lower().split())):
words.add(word.title())
words = sorted(words)
passwords = [
''.join(random.sample(words, args.num_words)) for _ in range(args.num)
]
if args.l33t:
passwords = map(l33t, passwords)
print('\n'.join(passwords))
# --------------------------------------------------
def clean(word):
"""Remove non-word characters from word"""
return re.sub('[^a-zA-Z]', '', word)
# --------------------------------------------------
def l33t(text):
"""l33t"""
text = ransom(text)
xform = str.maketrans({
'a': '@', 'A': '4', 'O': '0', 't': '+', 'E': '3', 'I': '1', 'S': '5'
})
return text.translate(xform) + random.choice(string.punctuation)
# --------------------------------------------------
def ransom(text):
"""Randomly choose an upper or lowercase letter to return"""
return ''.join(
map(lambda c: c.upper() if random.choice([0, 1]) else c.lower(), text))
# --------------------------------------------------
if __name__ == '__main__':
main()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.