rot13

Tuesday, June 08, 1999, at 12:17PM

By Eric Richardson

I was playing around with rot13 today. (rot13 transposes every letter 13 characters right. an 'a' becomes an 'n', an 'e' becomes an 'r', etc.) I then got bored, so I decided to play with it...

I came out with a little system like rot13, but with a rotation number that increments per character. So instead of 'hi' becoming 'uv', as it would in rot13, it becomes 'ik'. the h is transposed 1 char., the i is moved 2.

It produces some cool random junk looking text, such as:

ujlw ny h bnce as hwu vexlbakax bsqdhhgzbrxr elgiud. a kykaxr, shju lw ttsg j dpeg. wu jyal qznb y qebn hqjxnmwmj, u jcjbu jnh vja wnu xqxpi tvb ko yagwuyvv.

Here are the two Perl scripts I use:

rotN is the encoder script:

#!/usr/bin/perl
# -- generate rotN data -- #
%alpha = (a=>1,b=>2,c=>3,d=>4,e=>5,f=>6,g=>7,h=>8,i=>9,
j=>10,k=>11,l=>12,m=>13,n=>14,o=>15,p=>16,q=>17,
r=>18,s=>19,t=>20,u=>21,v=>22,w=>23,x=>24,y=>25,z=>26);

foreach my $letter (sort keys %alpha) {
$ralpha{$alpha{$letter}} = $letter;
}
do {
my $input = ;
chop $input;
my $results = &encode($input);
print "$results
";
} while (1);
sub encode {
my $output;
my $input = shift;
my $count;
my @letters = split("",$input);
while (my $letter = shift(@letters)) {
if ($letter !~ /[dW]/) {
$count++;
$letter =~ tr/A-Z/a-z/;
my $i_pos = $alpha{$letter};
my $o_pos = ($i_pos + $count);
unless ($o_pos <= 26) {
do {
$o_pos -= 26;
} until ($o_pos <= 26);
}
my $oletter = $ralpha{$o_pos};
$output .= "$oletter";
} else {
$output .= "$letter";
}
}
return $output;
}

and the decoder script, which I titled ripN:

#!/usr/bin/perl
# -- turn rotN data into plaintext-- #
%alpha = (a=>1,b=>2,c=>3,d=>4,e=>5,f=>6,g=>7,h=>8,i=>9,
j=>10,k=>11,l=>12,m=>13,n=>14,o=>15,p=>16,q=>17,
r=>18,s=>19,t=>20,u=>21,v=>22,w=>23,x=>24,y=>25,z=>26);
foreach my $letter (sort keys %alpha) {
$ralpha{$alpha{$letter}} = $letter;
}
do {
my $input = ;
chop $input;
my $results = &encode($input);
print "$results
";
} while (1);
sub encode {
my $output;
my $input = shift;
my $count;
my @letters = split("",$input);
while (my $letter = shift(@letters)) {
if ($letter !~ /[dW]/) {
$count++;
$letter =~ tr/A-Z/a-z/;
my $i_pos = $alpha{$letter};
my $o_pos = ($i_pos - $count);
if ($o_pos <= 0) {
do {
$o_pos += 26;
} until ($o_pos >= 0);
}
my $oletter = $ralpha{$o_pos};
$output .= "$oletter";
} else {
$output .= "$letter";
}
}
return $output;
}

Heh. More pointless fun...