% Biezl 2008
% shiftRegister := andvanced circuit
% shiftRegister2 := basic circuit
printf( "Definition: data(1,1)= Bit0/LSB data(1,lenght(data)) = MSB\n");
data = [1,0,0,0,1]
polynom = [1,1,0,0,1]
shiftRegister = zeros(1, length(polynom)-1);
size(shiftRegister)
size(data)
%----
for i=length(data):-1:1
temp = ( data(1,i) != shiftRegister(1,length(shiftRegister)) ); % MSB
for j=length(shiftRegister):-1:2 % Schieben
if polynom(1,j) == 0
shiftRegister(1,j) = shiftRegister(1,j-1);
else
shiftRegister(1,j) = shiftRegister(1,j-1) != temp; % XOR
end
end
shiftRegister(1,1) = temp; %LSB
% shiftRegister
end
%----
shiftRegister2 = zeros(1, length(polynom)-1);
dataExt = [zeros(1, length(polynom)-1), data];
for i=length(dataExt):-1:1
temp = ( dataExt(1,i) != shiftRegister2(1,length(shiftRegister2)) ); % MSB
temp2 = shiftRegister2(1,length(shiftRegister2));
for j=length(shiftRegister2):-1:2
if polynom(1,j) == 0
shiftRegister2(1,j) = shiftRegister2(1,j-1);
else
shiftRegister2(1,j) = shiftRegister2(1,j-1) != temp2;
end
end
shiftRegister2(1,1) = temp; %LSB
shiftRegister2
end
%----
check = [ shiftRegister, data ]; % LSB -> MSB
shiftRegisterCheck = zeros(1, length(polynom)-1);
for i=length(check):-1:1
temp = ( check(1,i) != shiftRegisterCheck(1,length(shiftRegisterCheck)) ); % MSB
for j=length(shiftRegisterCheck):-1:2
if polynom(1,j) == 0
shiftRegisterCheck(1,j) = shiftRegisterCheck(1,j-1);
else
shiftRegisterCheck(1,j) = shiftRegisterCheck(1,j-1) != temp;
end
end
shiftRegisterCheck(1,1) = temp; %LSB
% shiftRegisterCheck
end
%----
check2 = [ shiftRegister2, data ]; % LSB -> MSB
shiftRegisterCheck2 = zeros(1, length(polynom)-1);
for i=length(check2):-1:1
temp = ( check2(1,i) != shiftRegisterCheck2(1,length(shiftRegisterCheck2)) ); % MSB
temp2 = shiftRegisterCheck2(1,length(shiftRegisterCheck2)) ; % MSB
for j=length(shiftRegisterCheck2):-1:2
if polynom(1,j) == 0
shiftRegisterCheck2(1,j) = shiftRegisterCheck2(1,j-1);
else
shiftRegisterCheck2(1,j) = shiftRegisterCheck2(1,j-1) != temp2;
end
end
shiftRegisterCheck2(1,1) = temp; %LSB
%shiftRegisterCheck2
end
%----
shiftRegister
shiftRegisterCheck
shiftRegister2
shiftRegisterCheck2