rot13.pl

One of the first things I ever wrote in Perl was a simple ROT-13 encryption and decryption program. This started out as about 15-20 lines of Perl code, and as I got better and better understanding of Perl, I ended up with the script below.

The magic in this script comes in two separate parts. First of all, I use the -p switch to perl which causes it to do the following:

The other part of the magic happens in the tr-command. This command translates each character in the input ($_) by finding it in the first range and taking the corresponding index in the second range. In this way a gets turned into n and so on. The ranges given could equally well have been something like tr/a-zA-Z/n-za-mN-ZA-M/; but I found it a little more obfuscated the other way :-)

You can download the script here

#!/usr/bin/perl -p
tr/a-zN-ZA-M/n-za-mA-Z/;
Last updated: 2005.04.29