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. ;)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|