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

Discussion in 'Perl' started by `Zidane Tribal, Jul 26, 2007.

  1. 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.
     
    `Zidane Tribal, Jul 26, 2007
    #1
    1. Advertising

  2. `Zidane Tribal

    Joe Smith Guest

    `Zidane Tribal wrote:
    > 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.

    > 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.
     
    Joe Smith, Jul 28, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,213
    Smokey Grindel
    Dec 2, 2006
  2. Mamut

    crc-8 and crc-16 code...

    Mamut, Feb 21, 2007, in forum: C++
    Replies:
    5
    Views:
    4,138
    Victor Bazarov
    Feb 22, 2007
  3. Rastio Hodul

    Do I need CRC check on web service which returns byte array?

    Rastio Hodul, May 22, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    264
    AlexS
    May 22, 2004
  4. Michael Tan
    Replies:
    32
    Views:
    1,068
    Ara.T.Howard
    Jul 21, 2005
  5. `Zidane Tribal
    Replies:
    3
    Views:
    274
    Sisyphus
    Jul 27, 2007
Loading...

Share This Page