Zupelnie z ciekawosci... Zastanawiam sie jak kilka bajtow moze potwierdzic poprawnosc nawet bardzo duzego pliku. Co jest w sumie kontrolnej i jak jest obliczana?
tego chcieć... potem określiwszy parametry jak ilość danych i poziom wiarygodności dać to jakiemuś matematykowi aby opracował równanie - takie gdzie zmiana dowolnej liczby/sposobu bitów spowoduje inny wynik i ... zaimplementować... :)
co do obecnie stosowanych algorytmów - w normach dla niektórych urządzeń jest podawany algorytm do obliczania CRC aby się wszystko z całym innym światem owych urządzeń zgadzało...
CRC
1.sekwencja kodowa:
F= fn-1, fn-2,..., f0
fi {0,1}
2.wielomian kodowy
f(x)=fn-1xn-1+fn-2xn-2+...+f1
3.wielomian generuj. kod nadmiarowy
g(x)=xr+qr-1xr-1+...
gi {0,1}
zał. : A i B mają wspólne g
algorytm:
1.sekwencję kodową dzieli sie przez wielomian generacyjny
2.z dzielenia biorze sie resztę
3.sekw. kodowa i resztę przesyła sie do B (reszta z dzielenia to bity nadmiarowe)
4.w stacji B odbiera sie sekw. kod. i dzieli ją przez g – jeśli reszta z dzielenia wyszła taka, jak przysłało A, to jest OK
1
unit crc32;
{
/* ============================================================= */
/* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
*/
/* code or tables extracted from it, as desired without restriction.
*/
/*
*/
/* First, the polynomial itself and its table of feedback terms. The
*/
/* polynomial is
*/
/*
X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
/*
*/
/* Note that we take it "backwards" and put the highest-order term in
*/
/* the lowest-order bit. The X^32 term is "implied"; the LSB is the
*/
/* X^31 term, etc. The X^0 term (usually shown as "+1") results in
*/
/* the MSB being 1.
*/
/*
*/
/* Note that the usual hardware shift register implementation, which
*/
/* is what we're using (we're merely optimizing it by doing eight-bit
*/
/* chunks at a time) shifts bits into the lowest-order term. In our
*/
/* implementation, that means shifting towards the right. Why do we
*/
/* do it this way? Because the calculated CRC must be transmitted in
*/
/* order from highest-order term to lowest-order term. UARTs
transmit */
/* characters in order from LSB to MSB. By storing the CRC this way,
*/
/* we hand it to the UART in the order low-byte to high-byte; the
UART */
/* sends each low-bit to hight-bit; and the result is transmission
bit */
/* by bit from highest- to lowest-order term without requiring any
bit */
/* shuffling on our part. Reception works similarly.
*/
/*
*/
/* The feedback terms table consists of 256, 32-bit entries. Notes:
*/
/*
*/
/* The table can be generated at runtime if desired; code to do
so */
/* is shown later. It might not be obvious, but the feedback
*/
/* terms simply represent the results of eight shift/xor opera-
*/
/* tions for all combinations of data and CRC register values.
*/
/*
*/
/* The values must be right-shifted by eight bits by the "updcrc"
*/
/* logic; the shift must be unsigned (bring in zeroes). On some
*/
/* hardware you could probably optimize the shift in assembler by
*/
/* using byte-swap instructions.
*/
/* polynomial $edb88320
*/
/*
*/
/*
-------------------------------------------------------------------- */
}
interface
type
pbyte = ^byte;
longrec = record
lo,hi : word;
end;