"you need coolin', baby i'm not foolin' . . ." okay, so i am ;)
=head1 NAME Crypt::Rot26 - Encrypt data with TWICE the power of Rot13!! =head1 SYNOPSIS use strict; use Crypt::Rot26; my $crypt = Crypt::Rot26->new(); my $bonham = 'whole lotta luv!'; my $crypted = $crypt->crypt($bonham); print $crypted, "\n"; print $crypt->decrypt($crypted), "\n"; =cut package Crypt::Rot26; sub new { my ($proto) = @_; my $class = ref $proto || $proto; my $self = { rot => 26, offset => { map { $_ => 97, uc $_ => 65 } ('a'..'z') }, }; bless $self, $class; return $self; } sub crypt { do_it(@_,'+'); } sub decrypt { do_it(@_,'-'); } sub do_it { my ($self,$str,$op) = @_; my $crypted = ''; my $rotation = $self->{rot}; foreach my $chr (split('',$str)) { if ($chr =~ /[A-Za-z]/) { my $offset = $self->{offset}->{$chr}; my $shift = eval "$offset $op $rotation"; $chr = chr((ord($chr) - $shift) % 26 + $offset); } $crypted .= $chr; } return $crypted; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Crypt::Rot26
by Dragonfly (Priest) on Sep 25, 2001 at 20:32 UTC | |
|
Re: Crypt::Rot26
by ikegami (Patriarch) on Oct 01, 2010 at 18:43 UTC | |
by Anonymous Monk on Oct 04, 2010 at 16:37 UTC | |
|
Re: Crypt::Rot26
by jffry (Hermit) on Oct 01, 2010 at 18:09 UTC | |
|
Re: Crypt::Rot26
by Anonymous Monk on Sep 30, 2010 at 18:02 UTC | |
|
Re: Crypt::Rot26
by Anonymous Monk on May 27, 2012 at 00:35 UTC |