pwgen.pl
author Peter Gervai <grin@grin.hu>
Wed, 29 Sep 2021 23:17:35 +0200
changeset 6 78c000fd2ee7
parent 5 98bc7c6e581a
child 13 9ec5ecfe4347
permissions -rwxr-xr-x
Add perlgrok.pl: a logstash/grok compatible perl parser

#!/usr/bin/perl
# $Id: pwgen.pl,v 1ad4c2066b77 2020/12/09 14:56:54 grin $
# (c)Peter Gervai, 2002; Released under GPLv2 + CC_BY-SA-2.0
#
# jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09
#

use Getopt::Long;

my $help;
my $words=5;
my $syllab=4;
my $dash;
my $dashlen=2;
my $dashchr='-';
my $longsyl=20;
my $nolf=0;

GetOptions(
  "help" 	=> \&help,
  "words=i" 	=> \$words,
  "syllab=i"	=> \$syllab,
  "dash"	=> \$dash,
  "dashlen=i"	=> \$dashlen,
  "longsyl=i"	=> \$longsyl,
  "dashchr=s"	=> \$dashchr,
  "nolf"	=> \$nolf,
) or &help;


$vowel='aeiou';
#$cons='bcdfghjklmnpqrstvwxyz';
 $cons='bcdfghjklmnprstvxyz';

$vlen=length($vowel);
$clen=length($cons);

$longsyl=20; # percent

for (1..$words) {
    my $dash_count=0;
    my $sylnum=$syllab + rand(3);
    for my $i (1..$sylnum) {
        print substr($cons,rand($clen),1);
        print substr($vowel,rand($vlen),1);
        print substr($cons,rand($clen),1) if $longsyl > rand(100);
        print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
    }
    print "   " unless $words == 1;
}

print "\n" unless $nolf;


sub help {
    print "Usage:\n";
    print "  $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n";
    print "      words:   how many passwords to display\n";
    print "      syllab:  how many syllables in a word\n";
    print "      dash:    use dash between syllables\n";
    print "      dashlen: use dash between every N syllable\n";
    print "      longsyl: long syllable probability (percent)\n";
    print "      dashchr: character to use instead of '-'\n";
    print "      nolf:    don't print a linefeed after the last word\n";
    exit;
}