{ rotina de teste do crc por tabela e por calculo }

uses crt,crc;

var crcaccum: word;
    vet: array [0..1023] of byte;
    i: integer;
    salva: word;

procedure updcrc (c: byte);
var shifter, i: word;
    flag: boolean;
begin
    shifter := $80;
    while shifter <> 0 do
      begin
        flag := (crcaccum and $8000) <> 0;
        crcaccum := crcaccum shl 1;
        if (shifter and c) <> 0 then
          crcaccum := crcAccum or 1;
        if flag then
          crcaccum := crcaccum xor $1021;
        shifter := shifter shr 1;
      end;
end;

begin
    while not keypressed do
        begin
            for i := 0 to 1023 do
                vet [i] := random (256);

            crcAccum := 0;
            for i := 0 to 1023 do
                updcrc (vet[i]);
            write (crcAccum, ' ');
            salva := crcAccum;

            crcAccum := 0;
            for i := 0 to 1023 do
                atualizaCrc (crcAccum, vet[i]);

            writeln (crcAccum);
            if crcAccum <> salva then
               halt;
        end;
end.
