% Code is for Octave
%-----------------------------------%
%                                   %
% (C) 2014 - Michael K. Pellegrino  %
%                                   %
% My implementation of a Hill       %
% Cipher encoder.                   %
%                                   %
% usage: encrypthill( String, Key ) %
% where Key is a 2x2 matrix         %
%                                   %
%-----------------------------------%
function ret=encrypthill( S, K )
  ret=[];
  S=toupper(S);
  l=size(S)(2); %Get String length
  if( l/2 != floor(l/2) )
    S=[ S "." ];
  endif
  for i=1:l
      if( S(i) < 32 )
	S(i)=32;
      elseif( S(i) > 96 )
	S(i)=32;
      endif
  endfor

  if l<2
    return;
  endif
  
  S=toascii(S);
  S-=32;

  for i=1:2:l
    p=[ S(i) ; S(i+1) ];
    C=K*p;
    ret=[ ret mod(C(1),61) mod(C(2),61) ];
  endfor
  
  ret=char(ret);
endfunction
