pwgen.pl
changeset 3 d4bb4405d439
parent 0 624a9ab34425
child 4 414797051084
equal deleted inserted replaced
2:b78794f00e34 3:d4bb4405d439
     1 #!/usr/bin/perl
     1 #!/usr/bin/perl
     2 # $Id$
     2 # $Id: pwgen.pl,v 72a196c63f31 2020/12/09 14:24:36 grin $
     3 # (c)Peter Gervai, 2002; Released under GPLv2 + CC_BY-SA-2.0
     3 # (c)Peter Gervai, 2002; Released under GPLv2 + CC_BY-SA-2.0
     4 #
     4 #
     5 # jelszogenerator, 2002/04/08
     5 # jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09
     6 #
     6 #
     7 
     7 
     8 if( $ARGV[0] =~ /shutup/i ) { $shutup = 1; $num=1; } else { $num = 6; }
     8 use Getopt::Long;
       
     9 
       
    10 my $help;
       
    11 my $words=5;
       
    12 my $syllab=4;
       
    13 my $dash;
       
    14 my $dashlen=2;
       
    15 my $dashchr='-';
       
    16 my $longsyl=20;
       
    17 
       
    18 GetOptions(
       
    19   "help" 	=> \&help,
       
    20   "words=i" 	=> \$words,
       
    21   "syllab=i"	=> \$syllab,
       
    22   "dash"	=> \$dash,
       
    23   "dashlen=i"	=> \$dashlen,
       
    24   "longsyl=i"	=> \$longsyl,
       
    25   "dashchr=s"	=> \$dashchr,
       
    26 ) or &help;
       
    27 
     9 
    28 
    10 $vowel='aeiou';
    29 $vowel='aeiou';
    11 #$cons='bcdfghjklmnpqrstvwxyz';
    30 #$cons='bcdfghjklmnpqrstvwxyz';
    12  $cons='bcdfghjklmnprstvxyz';
    31  $cons='bcdfghjklmnprstvxyz';
    13 
    32 
    14 $vlen=length($vowel);
    33 $vlen=length($vowel);
    15 $clen=length($cons);
    34 $clen=length($cons);
    16 
    35 
       
    36 $longsyl=20; # percent
    17 
    37 
    18 $longsyl=20; # percent
    38 for (1..$words) {
    19 $sylnum=4 + rand(3);
    39     my $dash_count=0;
    20 
    40     my $sylnum=$syllab + rand(3);
    21 print "$num tok jo jelszo: " unless $shutup;
       
    22 
       
    23 
       
    24 
       
    25 for (1..$num) {
       
    26     for my $i (1..$sylnum) {
    41     for my $i (1..$sylnum) {
    27         print substr($cons,rand($clen),1);
    42         print substr($cons,rand($clen),1);
    28         print substr($vowel,rand($vlen),1);
    43         print substr($vowel,rand($vlen),1);
    29         print substr($cons,rand($clen),1) if $longsyl > rand(100);
    44         print substr($cons,rand($clen),1) if $longsyl > rand(100);
    30         #print "-";
    45         print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
    31     }
    46     }
    32     print "  " unless $shutup;
    47     print "   ";
    33 }
    48 }
    34 
    49 
    35 print "\n";
    50 print "\n";
    36 print "\n" unless $shutup;
    51 
       
    52 
       
    53 sub help {
       
    54     print "Usage:\n";
       
    55     print "  $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n";
       
    56     print "      words:   how many passwords to display\n";
       
    57     print "      syllab:  how many syllables in a word\n";
       
    58     print "      dash:    use dash between syllables\n";
       
    59     print "      dashlen: use dash between every N syllable\n";
       
    60     print "      longsyl: long syllable probability (percent)\n";
       
    61     print "      dashchr: character to use instead of '-'\n";
       
    62     exit;
       
    63 }