author | Peter Gervai <grin@grin.hu> |
Wed, 12 Apr 2023 20:16:17 +0200 | |
changeset 12 | 5301f455fc7f |
parent 5 | 98bc7c6e581a |
child 13 | 9ec5ecfe4347 |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/perl |
5
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
2 |
# $Id: pwgen.pl,v 1ad4c2066b77 2020/12/09 14:56:54 grin $ |
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
3 |
# (c)Peter Gervai, 2002; Released under GPLv2 + CC_BY-SA-2.0 |
0 | 4 |
# |
5
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
5 |
# jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09 |
0 | 6 |
# |
7 |
||
3
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
8 |
use Getopt::Long; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
9 |
|
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
10 |
my $help; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
11 |
my $words=5; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
12 |
my $syllab=4; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
13 |
my $dash; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
14 |
my $dashlen=2; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
15 |
my $dashchr='-'; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
16 |
my $longsyl=20; |
5
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
17 |
my $nolf=0; |
3
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
18 |
|
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
19 |
GetOptions( |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
20 |
"help" => \&help, |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
21 |
"words=i" => \$words, |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
22 |
"syllab=i" => \$syllab, |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
23 |
"dash" => \$dash, |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
24 |
"dashlen=i" => \$dashlen, |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
25 |
"longsyl=i" => \$longsyl, |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
26 |
"dashchr=s" => \$dashchr, |
5
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
27 |
"nolf" => \$nolf, |
3
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
28 |
) or &help; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
29 |
|
0 | 30 |
|
31 |
$vowel='aeiou'; |
|
32 |
#$cons='bcdfghjklmnpqrstvwxyz'; |
|
33 |
$cons='bcdfghjklmnprstvxyz'; |
|
34 |
||
35 |
$vlen=length($vowel); |
|
36 |
$clen=length($cons); |
|
37 |
||
38 |
$longsyl=20; # percent |
|
39 |
||
3
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
40 |
for (1..$words) { |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
41 |
my $dash_count=0; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
42 |
my $sylnum=$syllab + rand(3); |
0 | 43 |
for my $i (1..$sylnum) { |
44 |
print substr($cons,rand($clen),1); |
|
45 |
print substr($vowel,rand($vlen),1); |
|
46 |
print substr($cons,rand($clen),1) if $longsyl > rand(100); |
|
3
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
47 |
print $dashchr unless !$dash or ++$dash_count % $dashlen or $i>$sylnum-$dashlen; |
0 | 48 |
} |
5
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
49 |
print " " unless $words == 1; |
0 | 50 |
} |
51 |
||
5
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
52 |
print "\n" unless $nolf; |
3
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
53 |
|
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
54 |
|
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
55 |
sub help { |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
56 |
print "Usage:\n"; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
57 |
print " $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n"; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
58 |
print " words: how many passwords to display\n"; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
59 |
print " syllab: how many syllables in a word\n"; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
60 |
print " dash: use dash between syllables\n"; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
61 |
print " dashlen: use dash between every N syllable\n"; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
62 |
print " longsyl: long syllable probability (percent)\n"; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
63 |
print " dashchr: character to use instead of '-'\n"; |
5
98bc7c6e581a
pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents:
4
diff
changeset
|
64 |
print " nolf: don't print a linefeed after the last word\n"; |
3
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
65 |
exit; |
d4bb4405d439
pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
66 |
} |