This response may be merely intuitive... AND wrong! (I am neither a cryptographer nor a particularly good mathematician.) Nonetheless, here goes...
It seems to me (YMMV . caveat above) that splitting duped chars by a variety of little used chars (or, maybe most frequently used chars) has certain merit... because it makes usage-frequency testing slightly more complex and may thus throw off any brute force using frequency testing.
#!/usr/bin/perl
#!/usr/bin/perl
use strict;
use warnings;
use 5.012;
# See 910956.pl (re playfair cipher) for salt, key and encoding -- #
as a follow on, modify encoding with possibility of multiple
# (i,e. "varying" or "inconsistent") insertions between dup letters
my @range = ("Q","V","X","Y","Z",);
my $seen = "";
my $message = uc(<>);
$message =~ s/[^A-Z0-9]//gi; # remove punct, etc
$message =~ s/j/i/gi;
$message =~ s/q/O/gi; # replace [Qq] with [Oo]
$message =~ s/\s+//g; # remove spaces
$message .= "X" if length($message)%2==1; # make length an even va
+lue
my @char = split('', $message);
say "\n" . "-" x10 . "\n";
for my $char(@char) {
if ($seen eq ($char)) {
my $i = int(rand(4));
my $letter = $range[$i];
print $letter . $char; # recode as push to encoded arra
+y for later printing
} else { # as five char groups
print ($char); } # recode: ditto
$seen = $char;
}
say "\n";
The tested I/O includes (with apologies for the pre tags below)
Quoth the Raven, 'Nevermore!' ...or three (3) or four (4) words to that generally accepted effect.
----------
OUOTHTHERAVENXNEVERMOREORTHREXE3ORFOUR4WORDSTOTHATGENERALXLYACVCEPTEDEFYFECTX
^ ^ ^ ^^^^^ ^^^ ^^^^ ^^^ ^^^^ ^
# obviously, this has limitations:
The SECRET stash is located cinq feet below ground at 41.7N, 73.4W. Its key is X734ab#@17ffyj.
----------
THESECRETSTASHISLOCATEDCINOFEYETBELOWGROUNDAT417N734WITSKEYISX734AB17FVFYi
# meaning determinable from context ^^^ ^^^
# but the new key is corrupted... ^^^ ^^^ ^^
|