Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use common::sense;
- package Vigenere;
- use Moose;
- use autobox::Core;
- use Carp 'croak';
- use lib 'Strings';
- sub BUILD{
- my $self = shift;
- my (@w, @k);
- @w = split (//, $self->word);
- @k = split (//, $self->key);
- croak "'key' and 'word' are diferent lenght\n"
- if($#w != $#k);
- }
- has 'word' => (
- is => 'rw',
- isa => 'Str',
- required => 1,
- );
- has 'key' => (
- is => 'rw',
- isa => 'Str',
- required => 1,
- );
- has 'op' => (
- is => 'rw',
- isa => 'Str',
- required => 1,
- );
- sub gen{
- my $self = shift;
- my $opt = $self->op;
- my @word = split //, $self->word;
- my @key = split //, $self->key;
- my ($a, $tword);
- for ($a = 0; $a < @word; $a++){
- if(($word[$a] =~ /[a-zA-Z]/) and ($key[$a] =~ /[a-zA-Z]/)){
- $word[$a] = ord(uc($word[$a]));
- $key[$a] = ord(uc($key[$a]));
- if ($opt eq 'e'){$tword .= chr ((($word[$a] + $key[$a])%26) + 65)}
- if ($opt eq 'd'){$tword .= chr ((($word[$a] - $key[$a])%26) + 65)}
- }
- else{ croak "'word' and 'key' need to be only letter"}
- }
- return $tword;
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement