String::CRC crc function returns incorrect result, why?

Z

`Zidane Tribal

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.
 
S

Sisyphus

..
..
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$
..
..
can anyone explain what i am doing wrong?

I don't think you're doing anything wrong - they are apparently using
different algorithms.

String::CRC::Cksum ( http://search.cpan.org/~ahamm/String-CRC-Cksum-0.03/ )
claims to be compatible with the POSIX cksum program.

Cheers,
Rob
 
Z

`Zidane Tribal

Sisyphus said:
.
.
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$
.
.
can anyone explain what i am doing wrong?

I don't think you're doing anything wrong - they are apparently using
different algorithms.

String::CRC::Cksum ( http://search.cpan.org/~ahamm/String-CRC-Cksum-0.03/
) claims to be compatible with the POSIX cksum program.

Cheers,
Rob

but that then begs the question...... which is the *right* algorithm....
is there one standardised algorithm?

Thanks,
`Zidane.
 
S

Sisyphus

..
..
but that then begs the question...... which is the *right* algorithm....
is there one standardised algorithm?

The *right* algorithm is the one that best suits your purposes.
If you want a perl module that's going to produce the same values as 'cksum'
then it looks like you need String::CRC::Cksum.
But if you don't need something that matches 'cksum' you could use any one
of the other modules - or even something like Digest::MD5 (which is a core
module) or Digest::SHA.

Cheers,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top