Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > String::CRC crc function returns incorrect result, why?

Reply
Thread Tools

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

 
 
`Zidane Tribal
Guest
Posts: n/a
 
      07-26-2007
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.
 
Reply With Quote
 
 
 
 
Sisyphus
Guest
Posts: n/a
 
      07-27-2007

"`Zidane Tribal" <(E-Mail Removed)0m> wrote in message
news:KR8qi.137295$(E-Mail Removed)...
..
..
> 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

 
Reply With Quote
 
 
 
 
`Zidane Tribal
Guest
Posts: n/a
 
      07-27-2007
Sisyphus wrote:

>
> "`Zidane Tribal" <(E-Mail Removed)0m> wrote in message
> news:KR8qi.137295$(E-Mail Removed)...
> .
> .
>> 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.




--
You dont need a reason to help people. `Zidane Tribal.
 
Reply With Quote
 
Sisyphus
Guest
Posts: n/a
 
      07-27-2007

"`Zidane Tribal" <(E-Mail Removed)0m> wrote in message
news:zYjqi.84065$(E-Mail Removed)...
..
..
>
> 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

 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String::CRC crc function returns incorrect result, why? `Zidane Tribal Perl 1 07-28-2007 08:01 PM
crc-8 and crc-16 code... Mamut C++ 5 02-22-2007 02:22 PM
SQL request returns incorrect french characters hagar Java 1 11-02-2006 03:46 PM
Basic calculation returns incorrect values Dale Reed ASP .Net 3 10-09-2006 03:03 PM
Do I need CRC check on web service which returns byte array? Rastio Hodul ASP .Net Web Services 1 05-21-2004 11:28 PM



Advertisments