1

I have a problem with CRC. My message in hex is: 80 00 00 03 an the crc is f5 1f. I thought, the polynom is 0x1021 (crc-ccitt kermit). How to find out, what polynom the right one is? And how can I see, if I need it reversed and if the initial value is 0xffff or 0x0000 or something else? How can I calc the polynom I am searching for? Do I have to convert the 80 00 00 03 and the f5 f1 to BIN and then divide both? I tried to clac myself with the prog reveng, but that was not successful. Maybe because I have not all params -.-

I found a php-function HERE

but that will not calc the right sum for me. Maybe it is not CRC-CCITT KERMIT in that php-function

Community
  • 1
  • 1
noobee
  • 373
  • 1
  • 4
  • 10

1 Answers1

2

0x1ff5 is indeed the CRC-CCITT (Kermit) of 80 00 00 03. (It is apparently stored in little-endian order in your stream.)

The PHP code you found is for the false "CRC-CCITT", which you can find in the RevEng catalog here.

The true CRC-CCITT (Kermit) parameters are here in that catalog. The bits are reversed, so you use the polynomial reversed, 0x8408, and you shift the bits down instead of up. The initial register contents are zero, and there is no final exclusive-or.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • ah. Do I have to change the polynom from 0x1021 to 0x8408 and the $result from 0xFFFF to 0x0000 in the php-code ? And how can I shift down instead of up ? Sorry, can you help me again ? – noobee Oct 13 '16 at 18:05
  • 1
    [crcany](https://github.com/madler/crcany) will generate C code for any CRC, including this one. – Mark Adler Oct 13 '16 at 18:12
  • can you help me, how to use crcany in console, please?? – noobee Oct 13 '16 at 20:27
  • mhh, I changed the things in the php-code. but there is always the wrong crc-ccitt (kermit). – noobee Oct 13 '16 at 22:04
  • 1
    Don't shift up the message byte. Base the `if` statement on the low bit, not the high bit. Use the polynomial reversed. Initialize with zero. – Mark Adler Oct 14 '16 at 07:10
  • In the function I changed "$result = 0xffff;" to "$result = 0x0000;" and "0x1021" to "0x8408" and "if (($result <<= 1) & 0x10000)" to "if (($result <<= 1) & 0x00001)" and "$result &= 0xffff;" to "$result &= 0x0000;" But that is not right I think. Now my checksum is not f5 1f. Can you find the error? Is there something I forgot to change ? – noobee Oct 14 '16 at 20:51
  • 1
    You are still shifting up. You would need to look at the low bit _before_ shifting down, since it will be lost in the shift down, unlike when shifting up. – Mark Adler Oct 14 '16 at 21:03
  • Sorry, thats the part I dont understand :-( – noobee Oct 14 '16 at 21:08
  • 1
    I can't help you with basic programming. – Mark Adler Oct 14 '16 at 21:24
  • Yes, my php-knowledge is very low. Can you help me anyway with the right code, please? – noobee Oct 14 '16 at 21:39
  • Pity you can keep your knowledge for yourself :-( If you know the solution, why cant you tell it? :-( – noobee Oct 15 '16 at 19:22
  • THX 4 help. Got the solution in php. Works like a charm :-) – noobee Nov 21 '16 at 21:07