% The generator polynomial used in this programme 
% is p^3 + p^2 +1, n = 7, k = 4
clear ; clc

%%                 1      2     3        4        5        6      7      8       9        10     11      12      13      14     15        16                    
                
message_seqX = [0 0 0 0;0 0 0 1;0 0 1 0;0 1 0 0;1 0 0 0;0 0 1 1;0 1 1 0;1 1 0 0;1 0 0 1;0 1 0 1;1 0 1 0;0 1 1 1;1 1 1 0;1 1 0 1;1 0 1 1;1 1 1 1];
GenpolyG = [1 1 0 1 0 0 0;0 1 1 0 1 0 0;0 0 1 1 0 1 0;0 0 0 1 1 0 1];

codewords = rem(message_seqX*GenpolyG,2)

%%% Check for linearity property
% c9 = codewords(9,:);c13 = codewords(13,:);   %%%% Taking the code words c9 and c13
% c9mod2c13 = rem(c9 + c13,2); %%%% Adding c9 and c13 in modulo-2
% %%%% Searching whether this is another code word in C (code)
% %%% If yes wrýte the two one under the other 
% ir = 1;
% while ir <= length(codewords(:,1))
%     if num2str(c9mod2c13) == num2str(codewords(ir,:))
%     irc9mod2c13 = [ir c9mod2c13]  %%%% c9 added to c13 in modulo-2
%     %codewords(ir,:) %%%% the code word the same as c9 added to c13 in modulo-2
%     end
%     ir = ir + 1;
% end
% %%%% Check for cyclic property
% c91 = [c9(2:end) c9(1)];c92 = [c9(3:end) c9(1:2)];c93 = [c9(4:end) c9(1:3)];
% c94 = [c9(5:end) c9(1:4)];c95 = [c9(6:end) c9(1:5)];c96 = [c9(7) c9(1:6)];
% ir = 1;
% while ir <= length(codewords(:,1))
%     if num2str(c91) == num2str(codewords(ir,:))
%     irc91 = [ir c91]  %%%% c9 cylclicly shifted once
%     %codewords(ir,:) %%%% the code word the same as c91
%     end
%     if num2str(c92) == num2str(codewords(ir,:))
%     irc92 = [ir c92]  %%%% c9 cylclicly shifted twice
%     %codewords(ir,:) %%%% the code word the same as c92
%     end
%     if num2str(c93) == num2str(codewords(ir,:))
%     irc93 = [ir c93]  %%%% c9 cylclicly shifted three times
%     %codewords(ir,:) %%%% the code word the same as c93
%     end
%     ir = ir + 1;
% end