/
showpass
executable file
·81 lines (74 loc) · 2.02 KB
/
showpass
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
#!/usr/bin/python3
# jbin - Joe's miscellaneous scripts, tools and configs
# shwopass: Show a password so that it can be entered easily
# Copyright (C) 2021-2021 Johannes Bauer
#
# This file is part of jbin.
#
# jbin is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; this program is ONLY licensed under
# version 3 of the License, later versions are explicitly excluded.
#
# jbin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with jbin. If not, see <http://www.gnu.org/licenses/>.
#
# Johannes Bauer <JohannesBauer@gmx.de>
import getpass
import string
import math
password = getpass.getpass("Password: ")
def getgroup(char):
groups = {
"lower": set(string.ascii_lowercase),
"upper": set(string.ascii_uppercase),
"digits": set(string.digits),
}
for (name, chars) in groups.items():
if char in chars:
return name
return "unknown"
def split_group(group):
char = group[0]
grouptype = getgroup(char)
max_len = {
"lower": 5,
"upper": 5,
"digits": 4,
}.get(grouptype, 2)
if len(group) <= max_len:
return [ group ]
else:
result = [ ]
grpcount = math.ceil(len(group) / max_len)
average = len(group) / grpcount
indexsum = 0
index = 0
while index < len(group):
indexsum += average
previndex = index
index = round(indexsum)
if index >= len(group):
index = len(group)
result.append(group[previndex : index])
return result
groups = [ ]
last_group = None
for char in password:
this_group = getgroup(char)
if last_group != this_group:
# New group
groups.append(char)
last_group = this_group
else:
# Same group.
groups[-1] += char
split_groups = [ ]
for group in groups:
split_groups += split_group(group)
print(" ".join(split_groups))