%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright: 2010 Integrated Sytems Laboratory, ETH Zurich
%%            http://www.iis.ee.ethz.ch/~sha3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x = roundr(x)

for i=1:16,
    x(i+16) = mod(x(i) + x(i+16), 2^32);
end

for i=1:16,
    x(i) = bin2dec(dec2bin(circshift(double( dec2bin(x(i),32)-48 ),[0 -7]))');
end

for i=1:8,
    temp = x(i);
    x(i) = x(i+8);
    x(i+8) = temp;
end

for i=1:16,
    x(i) = bitxor(x(i), x(i+16));
end

for i=17:4:32,
    temp = x(i);
    x(i) = x(i+2);
    x(i+2) = temp;
    
    temp = x(i+1);
    x(i+1) = x(i+3);
    x(i+3) = temp;
end

%--------------------------------------------------------------------------

for i=1:16,
    x(i+16) = mod(x(i) + x(i+16), 2^32);
end

for i=1:16,
    x(i) = bin2dec(dec2bin(circshift(double(dec2bin(x(i),32)-48),[0 -11]))');
end

for i=1:8:16,
    temp = x(i);
    x(i) = x(i+4);
    x(i+4) = temp;
    
    temp = x(i+1);
    x(i+1) = x(i+5);
    x(i+5) = temp;
    
    temp = x(i+2);
    x(i+2) = x(i+6);
    x(i+6) = temp;
    
    temp = x(i+3);
    x(i+3) = x(i+7);
    x(i+7) = temp;
end

for i=1:16,
    x(i) = bitxor(x(i), x(i+16));
end

for i=17:2:32,
    temp = x(i);
    x(i) = x(i+1);
    x(i+1) = temp;
end

Generated on Fri Sep 24 10:39:12 CEST 2010
Home