Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Fast parsing for cypher block chaining

by Roy Johnson (Monsignor)
on Feb 28, 2006 at 18:09 UTC ( #533435=note: print w/replies, xml ) Need Help??


in reply to Fast parsing for cypher block chaining

I don't understand why you're putting 8 bytes at a time on the buffer. Is it just to ensure that you have an integer multiple of 8 bytes in your out_buffer? If so,
$bufsize = length $buffer; # Make sure it's an integer multiple of 8 by reducing by any remainder $bufsize -= $bufsize % 8; #you could copy substr($buffer, 0, $bufsize) if you wanted/needed to syswrite (OUTFILE, $buffer, $bufsize);

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Fast parsing for cypher block chaining
by ikegami (Pope) on Feb 28, 2006 at 18:12 UTC
    "I intend then to chain and blowfish it before syswriting the buffer back out to the encrypted file.", the OP said. Blowfish only works on 8 bytes of data at a time, so the OP is looking for an efficient method of dividing a string into 8 byte segments.
Re^2: Fast parsing for cypher block chaining
by fluffyvoidwarrior (Monk) on Feb 28, 2006 at 18:13 UTC
    cos Crypt::Blowfish works with 8 byte blocks. The disk reads and writes I'm doing in 64k chunks which seems about optimum. I'm then splitting the 64k buffer into 8 byte lumps for Blowfish.
      I suspect you will do no worse letting Perl handle the buffering for you:
      $/ = \8; # Read 8-byte records. Behind the scenes, Perl will do buffer +ing of reads. $out_buffer .= blowfishify($_) while <INFILE>; print OUTFILE $out_buffer;
      Alternatively, you could (with a sufficiently modern Perl) read from your buffer as if it were a filehandle, using the same $/ = \8 trick.
      open BUF, '<', \$buffer or die "$!: Could not open buffer\n"; $/ = \8; $out_buffer .= blowfishify($_) while <INFILE>; print OUTFILE $out_buffer;
      They're tidier ways of doing what you want, but you'd have to try them to see whether they buy or lose you any efficiency. My guess is that the I/O isn't going to be the bottleneck, anyway; the encryption is.

      Caution: Contents may have been coded under pressure.
        In the first snippet, you should move the print into the loop to avoid using gigabytes of memory. That seemed to be the point of the OP's buffering.
        $/ = \8; # Read 8-byte records. Behind the scenes, Perl will do buffer +ing of reads. print OUTFILE blowfishify($_) while <INFILE>;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://533435]
help
Chatterbox?
[ambrus]: thezip: is Activestate Perl usable for your scenario instead?
[MidLifeXis]: Yeah, --notest is good, not sure I would do --force.
[thezip]: It fails 2/10 tests in that group. What are the ramifications if I force it? What should I look for for?
[thezip]: I've migrated from ActiveState to Strawberry. No going back...
[thezip]: I'll try the --notest arg first when I get back from meetings (after lunch).
[thezip]: Thanks guys for your comments! :-)
[1nickt]: Quick survey: has anyone used or even heard of autobox?
[Corion]: thezip: I would expect some (fancier?) numeric formatting to fail from these test failures
[1nickt]: ( Sometimes when idle I browse remote corners of the code repo at $work ... usually this yields knowledge of projects to decline and coworkers to avoid ... )
[LanX]: sure

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (16)
As of 2017-03-23 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (290 votes). Check out past polls.