This old thing?! My first node here was a reply to you on this very same subject. :-)
I probably wouldn't write this as an OO module myself, but if I had to do it, I'd probably provide a constructor new() that took a single argument (the key phrase) and returned a Crypt::LewisCarrollCode object. I'd provide encrypt and decrypt methods which then took a scalar to encrypt or decrypt. So, you'd be able to do something like this
my $code = Crypt::LewisCarrollCode->new('This is a pass phrase'); my $encrypted = $code->encrypt("You will never decipher this!"); my $decrypted = $code->decrypt($encrypted);
You may want to be able to pass other things to your encrypt() and decrypt() methods such as an array, for instance. You might also want them to work incrementally. In other words, you might want the object to maintain state and write your encrypt and decrypt methods such that they always pick up where the last call left off. That would allow you to do things like this:
my $code = Crypt::LewisCarrollCode->new("this is a pass phrase"); my $encrypted = $code->encrypt('Four score and seven years ago, our ' +); $encrypted .= $code->encrypt('fathers brought forth, upon this cont +inent, '); $encrypted .= $code->encrypt('a new nation, conceived in liberty, ' +); $encrypted .= $code->encrypt('and dedicated to the proposition that + '); $encrypted .= $code->encrypt('"all men are created equal."'); my $Gettysburg_Address = $code->decrypt($encrypted);
That should give you some ideas for the interface. I'll leave the implementation as an exercise because you want it to be a learning experience anyway.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: My First Module: LewisCarrolCode.pm
by sauoq
in thread My First Module: LewisCarrolCode.pm
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |