pwgen.pl
author Peter Gervai <grin@grin.hu>
Wed, 09 Dec 2020 15:44:05 +0100
changeset 3 d4bb4405d439
parent 0 624a9ab34425
child 4 414797051084
permissions -rwxr-xr-x
pwgen.pl: Implement proper getopt, and install various knobs and wheels to make it shine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     1
#!/usr/bin/perl
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
     2
# $Id: pwgen.pl,v 72a196c63f31 2020/12/09 14:24:36 grin $
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     3
# (c)Peter Gervai, 2002; Released under GPLv2 + CC_BY-SA-2.0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     4
#
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
     5
# jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     6
#
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     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;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    17
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    18
GetOptions(
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    19
  "help" 	=> \&help,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    20
  "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
    21
  "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
    22
  "dash"	=> \$dash,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    23
  "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
    24
  "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
    25
  "dashchr=s"	=> \$dashchr,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    26
) or &help;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    27
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    28
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    29
$vowel='aeiou';
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    30
#$cons='bcdfghjklmnpqrstvwxyz';
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    31
 $cons='bcdfghjklmnprstvxyz';
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    32
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    33
$vlen=length($vowel);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    34
$clen=length($cons);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    35
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    36
$longsyl=20; # percent
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    37
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    38
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
    39
    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
    40
    my $sylnum=$syllab + rand(3);
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    41
    for my $i (1..$sylnum) {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    42
        print substr($cons,rand($clen),1);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    43
        print substr($vowel,rand($vlen),1);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    44
        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
    45
        print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    46
    }
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 "   ";
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    48
}
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    49
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    50
print "\n";
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    51
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    52
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    53
sub help {
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    54
    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
    55
    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
    56
    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
    57
    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
    58
    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
    59
    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
    60
    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
    61
    print "      dashchr: character to use instead of '-'\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    62
    exit;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    63
}