Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 26th, 2007, 10:05 PM
`Zidane Tribal
Guest
 
Posts: n/a
Default String::CRC crc function returns incorrect result, why?

it would appear that using the command 'crc("data")' from the String::CRC
returns incorrect results (although, they are at least consistently
incorrect).

for example, this script.....

#!/usr/bin/perl -w
use strict;
use String::CRC;
print "crc: " . crc($ARGV[0]) . " " . length($ARGV[0]) . "\n";

produces this output:

zidane@bluemist:~/ps2/dev/crccheck$ ./crctest.pl 12345
crc: 3817467633 5
zidane@bluemist:~/ps2/dev/crccheck$

whereas this command:

zidane@bluemist:~/ps2/dev/crccheck$ echo -n "12345" | cksum
3288622155 5
zidane@bluemist:~/ps2/dev/crccheck$

produces a different crc value.

this is also true using String::CRC32, DIGEST::CRC and DIGEST::CRC32 (using
the command line commands cksum and crc32 to create respective crc and
crc32 values to test against)

my query is simple.... why is this? although the values are different,
they are consistently different (i.e. the same result returned with each
call given the same data). can anyone explain what i am doing wrong?

`Zidane.
--
You dont need a reason to help people. `Zidane Tribal.
  #2  
Old July 28th, 2007, 09:05 PM
Joe Smith
Guest
 
Posts: n/a
Default Re: String::CRC crc function returns incorrect result, why?

`Zidane Tribal wrote:
Quote:
it would appear that using the command 'crc("data")' from the String::CRC
returns incorrect results
No, it's not. crc != cksum; there are many different CRC algorithms.
Quote:
for example, this script.....
>
#!/usr/bin/perl -w
use strict;
use String::CRC;
print "crc: " . crc($ARGV[0]) . " " . length($ARGV[0]) . "\n";
>
produces this output:
>
zidane@bluemist:~/ps2/dev/crccheck$ ./crctest.pl 12345
crc: 3817467633 5
zidane@bluemist:~/ps2/dev/crccheck$
>
whereas this command:
>
zidane@bluemist:~/ps2/dev/crccheck$ echo -n "12345" | cksum
3288622155 5
zidane@bluemist:~/ps2/dev/crccheck$
>
produces a different crc value.
The String::CRC::Cksum module calculates a 32 bit CRC, generating
the same CRC value as the POSIX cksum program.

linux% cat cksum.pl
#!/usr/bin/perl -w
use strict;
use String::CRC::Cksum qw(cksum);
print "cksum: " . cksum($ARGV[0]) . " " . length($ARGV[0]) . "\n";
linux% perl cksum.pl 12345
cksum: 3288622155 5


-Joe

P.S. The newsgroup comp.lang.perl is defunct; use comp.lang.perl.misc instead.
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles