You can use the "read" function to pull in any reasonable number of bytes you like into a scalar, and loop over substrings of the scalar to build up the corresponding number of output cipher bytes and print that to output.

I don't know enough about Twofish_PP (or other modules or conventions associated with this algorithm) to say what sort of formatting issues are assumed. Does the fact that it only deals with 16 bytes at a time mean that the output should be structured as lines of 16 characters terminated by newlines? Does this matter?

In any case, you also need to be careful when you reach the end-of-file, because chances are good the file size won't be a multiple of 16, and you'll need to pad the string. For example (not tested):

open( IN, "big.file" ) or die $!; while ( read( IN, my $cleartxt, 8192 ) > 0 ) { my $cryptxt = ""; while ( $cleartxt ) { $tocrypt = substr( $cleartxt, 0, 16 ); $cleartxt = substr( $cleartxt, 16 ); if ( length( $tocrypt ) != 16 ) { $tocrypt .= " " x ( 16 - length( $tocrypt )); } # do what you need with Twofish to encrypt, and # append result to $cryptxt } print $cryptxt; }

In reply to Re: Twofish_PP.pm by graff
in thread Twofish_PP.pm by Baratski

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.