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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.