| Uutiset | Koodikirjasto | Wiki | Keskustelut | FAQ | Info |
16-bit CRC-CCITTd0ggie 24.04.04 18:56 CCITT:n (Comité Consultatif International Téléphonique et Télégraphique) spesifikaation mukainen 16-bittisen CRC-tarkistuluvun laskentahärpäke.
<?php /* ================== 16-bit CRC-CCITT ------------------ Tehty seuraavan artikkelin perusteella: http://www.joegeluso.com/software/articles/ccitt.htm */ define('CRC16_POLY', 0x1021); class class_crc16_ccitt { function update_crc ($char, &$crc) { if (!isset($crc)) $crc = 0xffff; $char = ord($char); $v = 0x80; for ($i = 0; $i < 8; $i++) { $xor_flag = $crc & 0x8000 ? true : false; $crc <<= 1; $crc &= 0xffff; if ($char & $v) $crc += 1; if ($xor_flag) $crc ^= CRC16_POLY; $v >>= 1; } } function augment_message (&$crc) { for ($i = 0; $i < 16; $i++) { $xor_flag = $crc & 0x8000 ? true : false; $crc <<= 1; $crc &= 0xffff; if ($xor_flag) $crc ^= CRC16_POLY; } } } $string = '123456789'; $calc_crc = &new class_crc16_ccitt; for ($i = 0; $i < strlen($string); $i++) $calc_crc->update_crc($string[$i], $crc); $calc_crc->augment_message($crc); printf("'$string' -> 16-bit CRC-CCITT: 0x%04X\n", $crc); ?> gamestyle 10:33 24.5.04 Minä en kyllä ymmärtänyt ton selityksen perusteella, että mikä tämä on, enkä sen enempää koodinkaan. Liittyiskö jotenkin johonkin salaamiseen? bluebyte 14:51 7.6.04 varmaan jotain salakoodeja tarkistelee lahtis 20:25 15.7.04 voisitko tarkentaa hieman mitä tämä tekee.. Entropia 16:07 18.8.04 lahtis kirjoitti: voisitko tarkentaa hieman mitä tämä tekee.. Laskee CCITT:n spesifikaation mukaisen 16-bittisen tarkisteluvun. Voidaan käyttää esim. datan siirron oikeellisuuden tarkistuksessa (ettei tieto korruptoitunut matkalla). empty 15:12 29.3.05 "Suomeksi" laskee 16-bittisen CRC-hashin. tgs3 21:38 24.1.06 ja eikös tuo CRC ole saman tyylinen kuin MD5? |
![]() Haku
|