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
In reply to Re^3: encrypt and decrypt text
by davido
in thread encrypt and decrypt text
by pearlie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |