Code covered by the BSD License

# Transpozitie pe biti

by

### Cram200a (view profile)

Transpozitie pe biti

transp_b(text,k)
```function [c_txt] = transp_b(text,k)
% cu biti
txt_init=text;
n = length(text);  %nr de caractere
%transformare in binar (matrice cu bitii unui caracter pe o linie
text=dec2bin(text);

%transformare matrice in vector cu n*7 = 7simboluri pe caracter
text=reshape(text',1,7*n);
text=reshape(text,n,7)'; %matrice pe biti

c_txt=[];

i=1;
while(i*k<=n)

aux=text(:,1:k);
aux=reshape(aux',1,7*k); %primul set de coloane pus in linie
c_txt=[c_txt aux];
i=i+1;

text=text(: , k+1 : end); %matrice ramasa de reasezat
end

%coloanele ramase in numar mai mic de k
i=n-k*(i-1);
aux=text(: , end-i+1 : end);
aux=reshape(aux',1,7*i);
c_txt=[c_txt aux];

%reface caracterele
c_txt=reshape(c_txt,7,n)';
c_txt=char(bin2dec(c_txt))';

text=txt_init;
%histograme
h1=zeros(128);
h2=zeros(128);

for i=1:1:n
h1(text(i)) =h1(text(i)) +1;
h2(c_txt(i))=h2(c_txt(i))+1;
end

figure
subplot(2,1,1); plot(h1);
subplot(2,1,2); plot(h2);

end

```