buf(1)= hex2dec('A5');
buf(2)= hex2dec('3F');
buf(3)= hex2dec('01');
buf(4)= hex2dec('12');
buf(5)= hex2dec('00');
buf(6)= hex2dec('02');

Gr1 = hex2dec('0810');
accum = int(0);
for l = 1:6
    x = buf(l);
    for k = 0:7
        i = bitand(bitshift(x, -7), 1);
        if bitand(accum, hex2dec('8000'))
            accum = bitshift((accum ^ Gr1), 1) + (i ^ 1);
        else
            accum = bitshift(accum, 1) + i;
        end 
        accum = bitand(accum, hex2dec('FFFF'));
        x = bitshift(x, 1);
    end
end
dec2hex(accum)

            
            