function [code, genpoly, parityz, parityza] = rsencpz(msg, N, K)

M = msg.m;
t = (N-K)/2;
T2 = 2*t;       % pocet paritnich symbolu
n=N;
k=K;
msgZ=msg;
[m_msg, n_msg] = size(msg);
genpoly   = rsgenpoly(N,K,msg.prim_poly);   % generovani vytvareciho polynomu

parity = gf(zeros(m_msg,T2),M,msg.prim_poly);
parityza=parity;
genpoly = genpoly(2:T2+1);

% Kodovani
% Kazdy radek urcuje paritni symbol
for j=1:size(msgZ,2),
    parity = [parity(:,2:T2) zeros(m_msg,1)] + (msgZ(:,j)+parity(:,1))*genpoly;
end
      code = [msg parity]; % vlozeni paritnich symbolu za zpravu

parityza= [msg parityza];  
parityz= [parity];
