Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: encrypt and decrypt text

by davido (Cardinal)
on Feb 08, 2005 at 06:14 UTC ( [id://428945]=note: print w/replies, xml ) Need Help??


in reply to Re^2: encrypt and decrypt text
in thread encrypt and decrypt text

There's not much to explain. The English alphabet consists of 26 letters (A through Z). You just rotate the alphabet 13 places, and now you've got N through Z followed by A through N. The most common way to do that in Perl is to use the tr/// operator to rotate the alphabet through the magic of transliteration. Try this:

my $string = "Cleartext."; print $string, "\n"; $string = rot13( $string ); print $string, "\n"; $string = rot13( $string ); print $string, "\n"; sub rot13 { my $text = shift; $text = tr/A-Za-z/N-ZA-Mn-za-m/; return $text; }

Not exactly strong encryption. Most decent newsreaders will be able to rot-13 text. Its original use on the Net was to prevent children and employers from accidentally seeing a curse word in some Usenet post. But the concept has been around since 3rd grade 200 years ago when Cracker Jacks first started putting decoder rings in their popcorn boxes. ;)


Dave

Replies are listed 'Best First'.
Re^4: encrypt and decrypt text
by terra incognita (Pilgrim) on Feb 16, 2005 at 19:52 UTC
    It has been around a lot longer than that. :-) rot-13 is a form of Caesar cipher (which is named after for Julius Caesar) a good write up on it is at http://en.wikipedia.org/wiki/Caesar_cipher

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://428945]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found