Hints for Lab 3

Simple xor encryption:

  1. The instructions for encrypting each plaintext character must be repeated for all characters in the message. This suggests a loop:
       for i=1:length(message)
          ...  message(i) ...
       end
    
  2. Encrypted characters may be assembled into an encrypted string by means of the line
       enc = [enc encrypted_char];
    
    Similarly, decrypted characters may be assembled into a decrypted string by means of the line
       dec = [dec decrypted_char];
    
  3. The key_byte need only be computed one time - it should be done before the for loop.
  4. Decrypting is the same as encrypting except that it is the encrypted characters that are being xored instead of the plaintext characters. Therefore you can copy the encryption code block, paste it after the block, and make a very small modification to achieve decryption.
  5. To support encryption and decryption of more than one message you need to add another loop, outside the for loop discussed above.
  6. The structure of the program is as follows:
    	
       key = input('key> ');
       s = input('message> ','s');
       while length(s) != 0
          % encrypt message s
          ...
          % decrypt message s
          ...
          s = input('message> ','s');
       end
    

     

    RSA encryption:

    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); 
       end
    
    which 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).