[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] In search of a better rot13?



On Fri, Jan 07, 2000 at 08:03:51AM -0800, Brian McNett wrote:
> For various reasons I needed rot13 on my Mac.  Fairly simple to implement 
> in MacPerl, but this is a bit prolix:
> 
> #!perl -wpl
> tr/AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz/NnOoPpQqRrSsTtUuVvW
> wXxYyZzAaBbCcDdEeFfGgHhIiJjKkLlMm/
> 
> My apologies for the line wrapping.

Um...  It's much simpler than that.

tr/A-Za-z/N-ZA-Mn-za-m/;

> I use this as a "Perl Filter" in BBEdit. Better would be to reimplement 
> the Unix 'caesar' command, which I note is on the 'to-do' list for the 
> Perl Power Tools project.

#!/usr/local/bin/perl

$rot = shift;
$rot = 13 unless defined $rot;
$rot %= 26;

$replace = chr(ord('A')+$rot) . '-ZA-' . chr(ord('A')+$rot-1);
$replace .= lc($replace);

eval <<EOEVAL;
    while (<>) {
        tr/A-Za-z/$replace/;
        print;
    }
EOEVAL
__END__


Ronald

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org