in reply to Twofish_PP.pm
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Twofish_PP.pm
by tachyon (Chancellor) on May 24, 2004 at 03:03 UTC |