Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Encryption/Decryption Program:

by trizen (Hermit)
on May 07, 2014 at 10:03 UTC ( #1085294=note: print w/replies, xml ) Need Help??

in reply to Encryption/Decryption Program:

Here is a piece of code that I wrote about two years ago which does this (and more). Feel free to adjust it for your needs:
use 5.010; use strict; use warnings; sub encode_decode ($$) { my ($encode, $text) = @_; my $i = 1; my $output = ''; LOOP_1: foreach my $c (map ord, split //, $text) { foreach my $o ([32, 121]) { if ($c > $o->[0] && $c <= $o->[1]) { my $ord = $encode ? $c + ($i % 2 ? $i : -$i) : $c - ($i % 2 ? $i : -$i); if ($ord > $o->[1]) { $ord = $o->[0] + ($ord - $o->[1]); } elsif ($ord <= $o->[0]) { $ord = $o->[1] - ($o->[0] - $ord); } $output .= chr $ord; ++$i; next LOOP_1; } } $output .= chr($c); $i = 1; } return $output; } my $enc = encode_decode(1, q{this is a test}); my $dec = encode_decode(0, $enc); say "Enc: ", $enc; say "Dec: ", $dec; __END__ Enc: uflo jq b ucvp Dec: this is a test
Also, please see:

Replies are listed 'Best First'.
Re^2: Encryption/Decryption Program:
by tobyink (Abbot) on May 07, 2014 at 12:41 UTC


    use v5.14; sub encode_decode { shift =~ tr/A-Za-z/ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgf +edcba/r; } my $enc = encode_decode("this is a test"); my $dec = encode_decode($enc); say "Enc: ", $enc; say "Dec: ", $dec; __END__ Enc: gsrh rh z gvhg Dec: this is a test
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085294]
stevieb is writing a little CUFP on how to control analog pins on an arduino from a Linux machine via I2C in light of Perl, JavaScript and Strandbeests. It also is a good real-world use-case to test my I2C dist.
[stevieb]: I just don't feel like going hardcore on anything today, so I thought I'd *use* my software instead of just write it
[beech]: let the surprises begin :D

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2017-07-21 23:24 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (336 votes). Check out past polls.