This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randgen-catchy
executable file
·91 lines (75 loc) · 2.98 KB
/
randgen-catchy
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
#!/usr/bin/env python3
# many thanks to vain for this awesome work
# https://github.com/vain/bin-pub/blob/master/randgen-catchy
from argparse import ArgumentParser
from random import choice, randint
chars_start = list('bcdfghjklmnprstvwxz')
chars_vowels = list('aeiou') + ['ai', 'ao', 'au', 'ea', 'ee', 'ei',
'eu', 'ia', 'ie', 'oo', 'ou']
chars_cons = chars_start + ['bb', 'bl', 'cc', 'ch', 'ck', 'dd', 'dr',
'ds', 'dt', 'ff', 'gg', 'gn', 'kl', 'll',
'mb', 'md', 'mm', 'mp', 'mt', 'nc', 'nd',
'nn', 'np', 'nt', 'pp', 'rr', 'rt', 'sh',
'ss', 'st', 'tl', 'ts', 'tt']
def generate(words, per_word, digits):
pwd = ''
is_start = True
word_length = 0
words_done = 0
while words_done < words:
if is_start:
add = choice(chars_start).upper()
is_start = False
is_vowel = True
else:
if is_vowel:
add = choice(chars_vowels)
else:
add = choice(chars_cons)
is_vowel = not is_vowel
pwd += add
word_length += 1
if word_length == per_word:
pwd += '-'
word_length = 0
words_done += 1
is_start = True
pwd += str(randint(10**(digits - 1), 10**digits - 1))
return pwd
def complexity(words, per_word, digits):
if per_word % 2 == 1:
combis = ((len(chars_start) *
len(chars_vowels)**(per_word // 2) *
len(chars_cons)**(per_word // 2)
)**words
) * 10**digits
else:
combis = ((len(chars_start) *
len(chars_vowels)**(per_word // 2) *
len(chars_cons)**(per_word // 2 - 1)
)**words
) * 10**digits
ex = 1
while (26 + 26 + 10)**ex < combis:
ex += 1
ex -= 1
print('Words: {}, per word: {}, digits: {}'.format(words, per_word, digits))
print('Lengths of character classes: {}, {}, {}'.format(len(chars_start),
len(chars_vowels),
len(chars_cons)))
print()
print('Combinations: {}'.format(combis))
print()
print('This is better than a random alphanumeric string of {} characters,'.format(ex))
print('which would yield {} combinations.'.format((26 + 26 + 10)**ex))
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('-w', '--words', type=int, default=4)
parser.add_argument('-p', '--per-word', type=int, default=3)
parser.add_argument('-d', '--digits', type=int, default=2)
parser.add_argument('-c', '--complexity', action='store_true')
args = parser.parse_args()
if args.complexity:
complexity(args.words, args.per_word, args.digits)
else:
print(generate(args.words, args.per_word, args.digits))