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

Re: Re: Lewis Carroll's Code

by sauoq (Abbot)
on Jul 18, 2002 at 04:10 UTC ( [id://182702]=note: print w/replies, xml ) Need Help??


in reply to Re: Lewis Carroll's Code
in thread Lewis Carroll's Code

You might want to consider something like:
my @abc = ('a'..'z'); my %abc = map { ($abc[$_],$_) } (0..25); my @key = map { $abc{ lc() } } $key =~ /([a-z])/ig;
To use it, loop through the characters in your message any way you like. The following assumes you have the current letter in $c , that $i holds your position in @key , and that the result will be in $result . . .
my $new_c; if ($c =~ /[a-z]/i) { $new_c = $abc[($abc{lc($c)} + $key[$i]) % 26]; $new_c = uc($new_c) if ($c =~ /[A-Z]/); $result .= $new_c; $i = ($i + 1) % @key; } else { $result .= $c; }
You could use the same code above for decoding if you changed @key to hold negative numbers instead of positives.

-sauoq

"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found