pwgen.pl
author Peter Gervai <grin@grin.hu>
Wed, 15 May 2024 09:50:23 +0200
changeset 14 d2d8803e35ec
parent 13 9ec5ecfe4347
permissions -rwxr-xr-x
pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
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
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
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     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
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     6
#
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
     7
## This generator mimics Japanese syllable-based language, which
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
     8
## results easy to pronounce gibberish. 
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
     9
##
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    10
## Puroguramu o go riyo itadaki arigatogozaimasu. :-)
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    11
##
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    12
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    13
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
    14
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    15
my $help;                       # please?
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    16
my $words=5;                    # how many pw to be generated
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    17
my $syllab=4;                   # how many syllables in a [pass]word
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    18
my $dash;                       # use dashes
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    19
my $dashlen=2;                  # use dash after N syllable(s)
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    20
my $dashchr='-';                # dash character (if used)
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    21
my $longsyl=20;                 # long syllable n% probability
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    22
my $nolf=0;                     # no linefeed after the last word (script friendly)
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    23
my $hu_friendly = 5;           # n% probability of unfriendly consonants
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    24
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    25
GetOptions(
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    26
    "help" 	    => \&help,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    27
    "words=i" 	=> \$words,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    28
    "syllab=i"	=> \$syllab,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    29
    "dash"	    => \$dash,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    30
    "dashlen=i"	=> \$dashlen,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    31
    "longsyl=i"	=> \$longsyl,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    32
    "dashchr=s"	=> \$dashchr,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    33
    "nolf"	    => \$nolf,
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    34
    "hufriendly=i"=> \$hu_friendly,
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    35
) or &help;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    36
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    37
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    38
$vowel='aeiou';
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    39
#$cons='bcdfghjklmnpqrstvwxyz'; # consonants without visually confusing ones (like 0 vs o)
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    40
 $consh='bcdfghjklmnprstvz';    # non-English user friendly consonants 
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    41
 $consx='qxy';                  # for advanced speakers! ;-)
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    42
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    43
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    44
$vlen=length($vowel);
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    45
$chlen=length($consh);
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    46
$cxlen=length($consx);
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    47
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    48
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
    49
    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
    50
    my $sylnum=$syllab + rand(3);
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    51
    for my $i (1..$sylnum) {
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    52
        print &get_consonant;
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    53
        print substr($vowel,rand($vlen),1);
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    54
        print &get_consonant 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
    55
        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
    56
    }
5
98bc7c6e581a pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents: 4
diff changeset
    57
    print "   " unless $words == 1;
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    58
}
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    59
5
98bc7c6e581a pwgen.pl: option to skip LF at the end of the line
Peter Gervai <grin@grin.hu>
parents: 4
diff changeset
    60
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
    61
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    62
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    63
sub help {
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    64
    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
    65
    print "  $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n";
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    66
    print "      words:   how many passwords to display (5)\n";
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    67
    print "      syllab:  how many syllables in a word (4)\n";
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    68
    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
    69
    print "      dashlen: use dash between every N syllable\n";
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    70
    print "      longsyl: long syllable probability (20%)\n";
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    71
    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
    72
    print "      nolf:    don't print a linefeed after the last word\n";
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    73
    print "      hufriendly: probability of unfriendly consonants (5%)\n";
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    74
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    75
    exit;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    76
}
13
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    77
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    78
# Hungarian-friendly consonants
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    79
sub get_consonant {
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    80
    if( $hu_friendly > rand(100) ) {
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    81
        # be nasty to native speakers :-)
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    82
        return substr($consx, rand($cxlen),1);
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    83
    }
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    84
    return substr($consh, rand($chlen),1);
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    85
}
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    86
13
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    87
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    88
## syllables: 4 + rnd(3)			- ~1.5 bit
14
d2d8803e35ec pwgen.pl: support "hungarian-friendly" speaker mode, basically getting rid of 'qxy' with a given probability
Peter Gervai <grin@grin.hu>
parents: 13
diff changeset
    89
## cons:		rnd(20)				-  4.32 bit (a bit less due to hu_friendly)
13
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    90
## vow:			rnd(5)				-  2.32 bit
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    91
## cons2:		rnd(20) * 20%		- ~5.00 bit
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    92
##
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    93
##									- ~ 13.14 bit/syllable
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    94
## 4s: 52.5 b, 5s: 65.7 b, 6s: 78.8 b, 7s: 92 b
9ec5ecfe4347 pwgen: add comment about entropy calculation
Peter Gervai <grin@grin.hu>
parents: 5
diff changeset
    95
##