I have some data, hexadecimal encoded, that comes with a checksum:

 data : 26a435dea66b0200081c8f000e6f
 crc  : f497

I've tried the combinations of parameters for Digest::CRC that I could
think of (about 24) but have not found the right ones, for example the
script below.

Apparently, the C routine "yubikey_crc16" from "ykcrc.c" at
https://github.com/Yubico/yubico-c/blob/master/ykcrc.c
can generate such a checksum.

How can I get the same result from the module Digest::CRC?

Regards,
Lars

< CODE >

#!/usr/bin/perl

use strict;
use warnings;
use Digest::CRC;

# 26a435dea66b0200081c8f000e6ff497

my $msg = qq(26a435dea66b0200081c8f000e6f);
my $crc = qq(f497);

print qq(msg =$msg\n);
print qq(crc =$crc\n);

$msg = pack( 'H32', $msg ); # ???

my $ctx = Digest::CRC->new(width=>16, init=>0xffff, xorout=>0x0000,
                           refout=>1, poly=>0x8408, refin=>1, cont=>1);

$ctx->add($msg);
my $crc2 = $ctx->hexdigest;

print qq(crc2=$crc2\n\n);

< END OF CODE >

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to