% Code is for Octave
%-----------------------------------%
%                                   %
% (C) 2014 - Michael K. Pellegrino  %
%                                   %
% My implementation of an invers    %
% modulus calculator                %
%                                   %
% usage: imod( x, y )               %
%                                   %
%-----------------------------------%
function ret=imod( a, b )
  for i=1:b-1
    if( mod( i * a , b ) == 1 )
      ret=i;
      return;
    else
      ret=-1;
    endif
  endfor
endfunction
