Navigation

Doing It Twice Is Twice As Secure, Right?

Wednesday, January 31st, 2007

I was reading this article by my friend Patrick, and rather than comment on an old entry, I figure I would make a new one. Plus, this is the perfect chance to write a Perl One Liner!

perl -ple "y/[a-m][n-z][A-M][N-Z]/[n-z][a-m][N-Z][A-M]/"

Just pipe whatever you want to Rot13 into it. For best results: Print, Pipe, and Repeat.

Update: Shorter by two characters, and a bit clearer:

perl -ple "y/[a-m,A-M][n-z,N-Z]/[n-z,N-Z][a-m,A-M]/"

Update 2: Peter suggested this, and I don’t know why I didn’t think of it myself. Four characters shorter:

perl -ple "y/[a-mA-M][n-zN-Z]/[n-zN-Z][a-mA-M]/"

Comments

  1. Domain of the Bored » Blog Archive » ROT13 in Python replied on January 31st, 2007:

    […] Patr1ck has posted instructions on performing ROT13 in Ruby. Colin has responded with the Perl version. Here’s the Python version. import codecs rot13ed_data = codecs.getencoder(‘rot13’)(data_to_rot13)[0] […]

  2. Neil Rashbrook replied on September 18th, 2007:

    You’re still using the wrong syntax for the y operator, try perl -pe y/A-Za-z/N-ZA-Mn-za-m/

    Or why not use tr A-Za-z N-ZA-Mn-za-m