2 # $Id: pwgen.pl,v 1ad4c2066b77 2020/12/09 14:56:54 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 # (c)Peter Gervai, 2002; Released under GPLv2 + CC_BY-SA-2.0 |
4 # |
4 # |
5 # jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09 |
5 # jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09 |
6 # |
6 # |
|
7 ## This generator mimics Japanese syllable-based language, which |
|
8 ## results easy to pronounce gibberish. |
|
9 ## |
|
10 ## Puroguramu o go riyo itadaki arigatogozaimasu. :-) |
|
11 ## |
7 |
12 |
8 use Getopt::Long; |
13 use Getopt::Long; |
9 |
14 |
10 my $help; |
15 my $help; # please? |
11 my $words=5; |
16 my $words=5; # how many pw to be generated |
12 my $syllab=4; |
17 my $syllab=4; # how many syllables in a [pass]word |
13 my $dash; |
18 my $dash; # use dashes |
14 my $dashlen=2; |
19 my $dashlen=2; # use dash after N syllable(s) |
15 my $dashchr='-'; |
20 my $dashchr='-'; # dash character (if used) |
16 my $longsyl=20; |
21 my $longsyl=20; # long syllable n% probability |
17 my $nolf=0; |
22 my $nolf=0; # no linefeed after the last word (script friendly) |
|
23 my $hu_friendly = 5; # n% probability of unfriendly consonants |
18 |
24 |
19 GetOptions( |
25 GetOptions( |
20 "help" => \&help, |
26 "help" => \&help, |
21 "words=i" => \$words, |
27 "words=i" => \$words, |
22 "syllab=i" => \$syllab, |
28 "syllab=i" => \$syllab, |
23 "dash" => \$dash, |
29 "dash" => \$dash, |
24 "dashlen=i" => \$dashlen, |
30 "dashlen=i" => \$dashlen, |
25 "longsyl=i" => \$longsyl, |
31 "longsyl=i" => \$longsyl, |
26 "dashchr=s" => \$dashchr, |
32 "dashchr=s" => \$dashchr, |
27 "nolf" => \$nolf, |
33 "nolf" => \$nolf, |
|
34 "hufriendly=i"=> \$hu_friendly, |
28 ) or &help; |
35 ) or &help; |
29 |
36 |
30 |
37 |
31 $vowel='aeiou'; |
38 $vowel='aeiou'; |
32 #$cons='bcdfghjklmnpqrstvwxyz'; |
39 #$cons='bcdfghjklmnpqrstvwxyz'; # consonants without visually confusing ones (like 0 vs o) |
33 $cons='bcdfghjklmnprstvxyz'; |
40 $consh='bcdfghjklmnprstvz'; # non-English user friendly consonants |
|
41 $consx='qxy'; # for advanced speakers! ;-) |
|
42 |
34 |
43 |
35 $vlen=length($vowel); |
44 $vlen=length($vowel); |
36 $clen=length($cons); |
45 $chlen=length($consh); |
37 |
46 $cxlen=length($consx); |
38 $longsyl=20; # percent |
|
39 |
47 |
40 for (1..$words) { |
48 for (1..$words) { |
41 my $dash_count=0; |
49 my $dash_count=0; |
42 my $sylnum=$syllab + rand(3); |
50 my $sylnum=$syllab + rand(3); |
43 for my $i (1..$sylnum) { |
51 for my $i (1..$sylnum) { |
44 print substr($cons,rand($clen),1); |
52 print &get_consonant; |
45 print substr($vowel,rand($vlen),1); |
53 print substr($vowel,rand($vlen),1); |
46 print substr($cons,rand($clen),1) if $longsyl > rand(100); |
54 print &get_consonant if $longsyl > rand(100); |
47 print $dashchr unless !$dash or ++$dash_count % $dashlen or $i>$sylnum-$dashlen; |
55 print $dashchr unless !$dash or ++$dash_count % $dashlen or $i>$sylnum-$dashlen; |
48 } |
56 } |
49 print " " unless $words == 1; |
57 print " " unless $words == 1; |
50 } |
58 } |
51 |
59 |
53 |
61 |
54 |
62 |
55 sub help { |
63 sub help { |
56 print "Usage:\n"; |
64 print "Usage:\n"; |
57 print " $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n"; |
65 print " $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n"; |
58 print " words: how many passwords to display\n"; |
66 print " words: how many passwords to display (5)\n"; |
59 print " syllab: how many syllables in a word\n"; |
67 print " syllab: how many syllables in a word (4)\n"; |
60 print " dash: use dash between syllables\n"; |
68 print " dash: use dash between syllables\n"; |
61 print " dashlen: use dash between every N syllable\n"; |
69 print " dashlen: use dash between every N syllable\n"; |
62 print " longsyl: long syllable probability (percent)\n"; |
70 print " longsyl: long syllable probability (20%)\n"; |
63 print " dashchr: character to use instead of '-'\n"; |
71 print " dashchr: character to use instead of '-'\n"; |
64 print " nolf: don't print a linefeed after the last word\n"; |
72 print " nolf: don't print a linefeed after the last word\n"; |
|
73 print " hufriendly: probability of unfriendly consonants (5%)\n"; |
|
74 |
65 exit; |
75 exit; |
|
76 } |
|
77 |
|
78 # Hungarian-friendly consonants |
|
79 sub get_consonant { |
|
80 if( $hu_friendly > rand(100) ) { |
|
81 # be nasty to native speakers :-) |
|
82 return substr($consx, rand($cxlen),1); |
|
83 } |
|
84 return substr($consh, rand($chlen),1); |
66 } |
85 } |
67 |
86 |
68 |
87 |
69 ## syllables: 4 + rnd(3) - ~1.5 bit |
88 ## syllables: 4 + rnd(3) - ~1.5 bit |
70 ## cons: rnd(20) - 4.32 bit |
89 ## cons: rnd(20) - 4.32 bit (a bit less due to hu_friendly) |
71 ## vow: rnd(5) - 2.32 bit |
90 ## vow: rnd(5) - 2.32 bit |
72 ## cons2: rnd(20) * 20% - ~5.00 bit |
91 ## cons2: rnd(20) * 20% - ~5.00 bit |
73 ## |
92 ## |
74 ## - ~ 13.14 bit/syllable |
93 ## - ~ 13.14 bit/syllable |
75 ## 4s: 52.5 b, 5s: 65.7 b, 6s: 78.8 b, 7s: 92 b |
94 ## 4s: 52.5 b, 5s: 65.7 b, 6s: 78.8 b, 7s: 92 b |