% Modular exponentiation for RSA encryption and decryption
% from MathWorks
% Usage:
%  Base = message to be encrypted or decrypted
%  Exponent = either the public key "e" for encryption or
%             the private key "d" for decryption
%  Modulus = product of distinct primes p,q used by RSA.
% 
function Result = crypt(Base, Exponent, Modulus)
    Result          = 1;
    TempExponent    = 0;
    while true
        TempExponent    = TempExponent + 1;        
        Result          = mod((Base .* Result), Modulus);
        if TempExponent == Exponent
            break
        end
    end
end
