#!/usr/bin/perl -w
use strict;
# http://www.j-bradford-delong.net/movable_type/archives/000393.html
# Randomising letters in the middle of words has little or no effect
# on the ability of skilled readers to understand the text; Dave Long
# illustrated this in a FoRKpost in which only the first two letters
# and the last two letters were left the same, while the others were
# arbitrarily reordered.
# This program does that.
# Its -a flag orders the letters deterministically. Running this on
# /usr/share/dict/words (with sort | uniq -c | perl -ane 'print unless
# $F[0] eq "1"') shows that this transform destroys very little
# information; out of the 45392 words therein, only 80 become
# ambiguous through this transformation, and none have more than two
# possibilities.
# I used the -a option to generate this version of the program, but
# then I had to correct "stirct" and "legnth".
sub scabmrle {
my ($str) = @_;
my @leettrs = split //, $str;
for my $i (0..$#leettrs) {
my $j = int rand ($i + 1);
($leettrs[$i], $leettrs[$j]) = ($leettrs[$j], $leettrs[$i]);
}
return @leettrs;
}
sub alabehiptze {
my ($str) = @_;
my @leettrs = split //, $str;
return sort @leettrs;
}
my $trafnosrm = \&scabmrle;
sub misspell_word {
my ($word) = @_;
return $word if $word !~ /^\w+$/;
return $word if length $word < 6;
return (substr($word, 0, 2),
$trafnosrm->(substr($word, 2, -2)),
substr($word, -2));
}
sub miellpssed {
my ($line) = @_;
my @chnuks = split /\b([a-zA-Z]+)\b/, $line;
return map { misspell_word $_ } @chnuks;
}
if (defined $ARGV[0] and $ARGV[0] eq '-a') {
shift;
$trafnosrm = \&alabehiptze;
}
while (<>) {
print miellpssed $_;
}
--
<[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kragen/>
Edsger Wybe Dijkstra died in August of 2002. The world has lost a great
man. See http://advogato.org/person/raph/diary.html?start=252 and
http://www.kode-fu.com/geek/2002_08_04_archive.shtml for details.