Connecting Tech Pros Worldwide Help | Site Map

Replicating Perl's unpack functionality in C#

Newbie
 
Join Date: Oct 2008
Posts: 1
#1: Oct 8 '08
Hi,

I am trying to recreate a perl script in C# but have a problem creating a checksum value that a target system needs.

In Perl this checksum is calculated using the unpack function:
Expand|Select|Wrap|Line Numbers
  1. while () {
  2. $checksum += unpack("%32C*", $_);
  3. }
  4. $checksum %= 32767;
  5. close(PACKAGE);
  6. }
where PACKAGE is the .tar file input stream

I need to replicate this in C# but can't find a means of replicating that unpack function.

All help appreciated!

(I know there are much better checksum calculations available but can't change target system so can't change calculation)
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,158
#2: Oct 9 '08

re: Replicating Perl's unpack functionality in C#


My perl is a bit rusty, but it looks like unpack just pulls out a list of variables from a binary string.
%32C says to produce a 32bit checksum of the object instead of the object itself (Presumably the C just tells it to produce a "hex"-string by using unsigned characters?)

I guess you would have to find out what the checksum method they use is and implement that.
Reply