disp('********************************************************************') disp('Computes b^(-1) mod n according to the extended euclidean algorithm ') disp('********************************************************************') disp(' ') b=input ('Give me b= '); n=input ('Give me ö(n)= '); to=0; t=1; no=n; bo=b; q=floor(no/bo); r=no-q.*bo; while r>0 temp=to-q*t; if temp >=0 temp=mod(temp,n); temp=n-mod(-temp,n); to=t; t=temp; no=bo; bo=r; q=floor(no/bo); r=no-q*bo; else temp=n-mod(-temp,n); to=t; t=temp; no=bo; bo=r; q=floor(no/bo); r=no-q*bo; end end if bo~=1 disp('b has no inverse modulo') else The_inverse_modulo_of_b =mod(t,n) end disp('Implementation by Diomedes Kastanis')