Alphabet: abcdef
Translation: d a c
####
my $alpha = "abcdef";
my $cipher = "abcadbbe";
my $word = "deadbeef";
extend_translation( $alpha, " ", $cipher, $word );
# should return "deabf "
# note that when the entire translation is given as
# only ' 's, this sub should always return a new
# translation string
extend_translation( $alpha, " c", $cipher, $word );
# should return "deabfc"
extend_translation( $alpha, "c ", $cipher, $word );
# should return 0 or undef, since cipher 'a' is already
# representing normal 'c', and the two words would
# require that 'a' means 'd', instead, so the
# translation cannot work in this case.
my $tr = extend_translation( $alpha, " ", "ebba", "feed" );
# after this step, $tr = "de f "
if ( $tr ) {
$tr = extend_translation( $alpha, $tr, $cipher, $word );
# after this step, $tr = "deabf "
}
####
my $alpha = "elprxyz";
my $cipher = "zyxe";
my $normal = "perl";
my @array = translation_set( $alpha, $cipher, $normal );
foreach my $trans ( @array ) {
$_ = $cipher;
eval "tr/$alpha/$trans/"; #need to eval in order to
#expand variables
print $trans, ": ", $_,"\n";
}
# Would expect (but not necessarily in this order:)
# lxyzrep: perl
# lxzyrep: perl
# lyxzrep: perl
# lyzxrep: perl
# lzxyrep: perl
# lzyzrep: perl