pwgen.pl
changeset 5 98bc7c6e581a
parent 4 414797051084
child 13 9ec5ecfe4347
equal deleted inserted replaced
4:414797051084 5:98bc7c6e581a
     1 #!/usr/bin/perl
     1 #!/usr/bin/perl
     2 # $Id: pwgen.pl,v 72a196c63f31 2020/12/09 14:24:36 grin $
     2 # $Id: pwgen.pl,v 1ad4c2066b77 2020/12/09 14:56:54 grin $
       
     3 # (c)Peter Gervai, 2002; Released under GPLv2 + CC_BY-SA-2.0
     3 #
     4 #
     4 # (c)Peter Gervai, 2002-2020; Released under GPLv3+ + CC_BY-SA-4.0
     5 # jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09
     5 #
       
     6 # Password generator, 2002/04/08; 2016/11/09; 2020/12/09
       
     7 #
       
     8 # This code generates easy (easier) to spell and remember passwords.
       
     9 # The length, in-dashes and plenty of stuff are configurable.
       
    10 #
     6 #
    11 
     7 
    12 use Getopt::Long;
     8 use Getopt::Long;
    13 
     9 
    14 my $help;
    10 my $help;
    16 my $syllab=4;
    12 my $syllab=4;
    17 my $dash;
    13 my $dash;
    18 my $dashlen=2;
    14 my $dashlen=2;
    19 my $dashchr='-';
    15 my $dashchr='-';
    20 my $longsyl=20;
    16 my $longsyl=20;
       
    17 my $nolf=0;
    21 
    18 
    22 GetOptions(
    19 GetOptions(
    23   "help" 	=> \&help,
    20   "help" 	=> \&help,
    24   "words=i" 	=> \$words,
    21   "words=i" 	=> \$words,
    25   "syllab=i"	=> \$syllab,
    22   "syllab=i"	=> \$syllab,
    26   "dash"	=> \$dash,
    23   "dash"	=> \$dash,
    27   "dashlen=i"	=> \$dashlen,
    24   "dashlen=i"	=> \$dashlen,
    28   "longsyl=i"	=> \$longsyl,
    25   "longsyl=i"	=> \$longsyl,
    29   "dashchr=s"	=> \$dashchr,
    26   "dashchr=s"	=> \$dashchr,
       
    27   "nolf"	=> \$nolf,
    30 ) or &help;
    28 ) or &help;
    31 
    29 
    32 
    30 
    33 $vowel='aeiou';
    31 $vowel='aeiou';
    34 #$cons='bcdfghjklmnpqrstvwxyz';
    32 #$cons='bcdfghjklmnpqrstvwxyz';
    46         print substr($cons,rand($clen),1);
    44         print substr($cons,rand($clen),1);
    47         print substr($vowel,rand($vlen),1);
    45         print substr($vowel,rand($vlen),1);
    48         print substr($cons,rand($clen),1) if $longsyl > rand(100);
    46         print substr($cons,rand($clen),1) if $longsyl > rand(100);
    49         print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
    47         print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
    50     }
    48     }
    51     print "   ";
    49     print "   " unless $words == 1;
    52 }
    50 }
    53 
    51 
    54 print "\n";
    52 print "\n" unless $nolf;
    55 
    53 
    56 
    54 
    57 sub help {
    55 sub help {
    58     print "Usage:\n";
    56     print "Usage:\n";
    59     print "  $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n";
    57     print "  $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n";
    61     print "      syllab:  how many syllables in a word\n";
    59     print "      syllab:  how many syllables in a word\n";
    62     print "      dash:    use dash between syllables\n";
    60     print "      dash:    use dash between syllables\n";
    63     print "      dashlen: use dash between every N syllable\n";
    61     print "      dashlen: use dash between every N syllable\n";
    64     print "      longsyl: long syllable probability (percent)\n";
    62     print "      longsyl: long syllable probability (percent)\n";
    65     print "      dashchr: character to use instead of '-'\n";
    63     print "      dashchr: character to use instead of '-'\n";
       
    64     print "      nolf:    don't print a linefeed after the last word\n";
    66     exit;
    65     exit;
    67 }
    66 }