pwgen.pl
changeset 14 d2d8803e35ec
parent 13 9ec5ecfe4347
--- a/pwgen.pl	Wed May 15 09:04:25 2024 +0200
+++ b/pwgen.pl	Wed May 15 09:50:23 2024 +0200
@@ -4,46 +4,54 @@
 #
 # jelszogenerator, 2002/04/08; 2016/11/09; 2020/12/09
 #
+## This generator mimics Japanese syllable-based language, which
+## results easy to pronounce gibberish. 
+##
+## Puroguramu o go riyo itadaki arigatogozaimasu. :-)
+##
 
 use Getopt::Long;
 
-my $help;
-my $words=5;
-my $syllab=4;
-my $dash;
-my $dashlen=2;
-my $dashchr='-';
-my $longsyl=20;
-my $nolf=0;
+my $help;                       # please?
+my $words=5;                    # how many pw to be generated
+my $syllab=4;                   # how many syllables in a [pass]word
+my $dash;                       # use dashes
+my $dashlen=2;                  # use dash after N syllable(s)
+my $dashchr='-';                # dash character (if used)
+my $longsyl=20;                 # long syllable n% probability
+my $nolf=0;                     # no linefeed after the last word (script friendly)
+my $hu_friendly = 5;           # n% probability of unfriendly consonants
 
 GetOptions(
-  "help" 	=> \&help,
-  "words=i" 	=> \$words,
-  "syllab=i"	=> \$syllab,
-  "dash"	=> \$dash,
-  "dashlen=i"	=> \$dashlen,
-  "longsyl=i"	=> \$longsyl,
-  "dashchr=s"	=> \$dashchr,
-  "nolf"	=> \$nolf,
+    "help" 	    => \&help,
+    "words=i" 	=> \$words,
+    "syllab=i"	=> \$syllab,
+    "dash"	    => \$dash,
+    "dashlen=i"	=> \$dashlen,
+    "longsyl=i"	=> \$longsyl,
+    "dashchr=s"	=> \$dashchr,
+    "nolf"	    => \$nolf,
+    "hufriendly=i"=> \$hu_friendly,
 ) or &help;
 
 
 $vowel='aeiou';
-#$cons='bcdfghjklmnpqrstvwxyz';
- $cons='bcdfghjklmnprstvxyz';
+#$cons='bcdfghjklmnpqrstvwxyz'; # consonants without visually confusing ones (like 0 vs o)
+ $consh='bcdfghjklmnprstvz';    # non-English user friendly consonants 
+ $consx='qxy';                  # for advanced speakers! ;-)
+
 
 $vlen=length($vowel);
-$clen=length($cons);
-
-$longsyl=20; # percent
+$chlen=length($consh);
+$cxlen=length($consx);
 
 for (1..$words) {
     my $dash_count=0;
     my $sylnum=$syllab + rand(3);
     for my $i (1..$sylnum) {
-        print substr($cons,rand($clen),1);
+        print &get_consonant;
         print substr($vowel,rand($vlen),1);
-        print substr($cons,rand($clen),1) if $longsyl > rand(100);
+        print &get_consonant if $longsyl > rand(100);
         print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
     }
     print "   " unless $words == 1;
@@ -55,19 +63,30 @@
 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 "      words:   how many passwords to display (5)\n";
+    print "      syllab:  how many syllables in a word (4)\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 "      longsyl: long syllable probability (20%)\n";
     print "      dashchr: character to use instead of '-'\n";
     print "      nolf:    don't print a linefeed after the last word\n";
+    print "      hufriendly: probability of unfriendly consonants (5%)\n";
+
     exit;
 }
 
+# Hungarian-friendly consonants
+sub get_consonant {
+    if( $hu_friendly > rand(100) ) {
+        # be nasty to native speakers :-)
+        return substr($consx, rand($cxlen),1);
+    }
+    return substr($consh, rand($chlen),1);
+}
+
 
 ## syllables: 4 + rnd(3)			- ~1.5 bit
-## cons:		rnd(20)				-  4.32 bit
+## cons:		rnd(20)				-  4.32 bit (a bit less due to hu_friendly)
 ## vow:			rnd(5)				-  2.32 bit
 ## cons2:		rnd(20) * 20%		- ~5.00 bit
 ##