Hello,
J'ai un petit challenge à compléter.
Pour cela je dois utiliser la fonction CRC64 donnée ci-dessous en php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 function crc64($string) { $poly = (0xC96C5795 << 32) | 0xD7870F42; $crc = 0; for($i=0;$i<strlen($string);$i++) { $byte = ord($string[$i]); for($bit=0;$bit<8;$bit++,$byte>>=1) { $crc = (($crc>>1)& ~(1<<63)) ^ ((($crc^$byte)&1)?$poly:0); } } return $crc; }
Que j'ai réecrit en C ainsi :
Le soucis est que je devrais récupérer un CRC de 8 octets or la fonction renvoie un CRC de 4 octets.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 unsigned long long int crc64( char* s ) { unsigned long long int poly = (0xC96C5795ULL << 32) | 0xD7870F42; unsigned long long int crc = 0x0; for ( size_t i=0 ; i< strlen(s) ; i++ ) { unsigned long long int byte = s[i]; for ( size_t bit=0 ; bit<8 ; bit++, byte>>=1 ) crc = (( crc>>1 )&~(1ULL<<63)) ^ ((( crc^byte )&1 )?poly:0 ); } return crc; }
Je n'arrive pas à déterminer l'origine de ce problème.
Me retourne CRC = 0xe7197349
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 int main() { printf("\nNumber of bits for unsigned long long int type : %u", 8*sizeof(unsigned long long int)); printf("\n CRC = %x", crc64("t" )); return 0; }
Mais il en manque la moitié sauf mauvaise compréhension de ma part.
Merci d'avance.
Partager