Simple xor encryption:
for i=1:length(message) ... message(i) ... end
enc = [enc encrypted_char];Similarly, decrypted characters may be assembled into a decrypted string by means of the line
dec = [dec decrypted_char];
key = input('key> '); s = input('message> ','s'); while length(s) != 0 % encrypt message s ... % decrypt message s ... s = input('message> ','s'); end
The suggested function modpow is the key to success. If you do not understand the description of an efficient implementation as given in the lab assignment just try this:
accu = 1; for i=1:expon accu = mod(accu*base,modulus); endwhich results in a value of accu equal to base raised to the expon power, taken mod modulus. This is a lot slower than the suggested implementation but will do the job - (not suitable for a real application, however).