% function to read in a file and applies a different
% shift to each letter. The shifts are generated by a
% integer seed value that is entered as a input
% In this code we remove the blank spaces

function   rs2(filename,seed)
   % read in file to be encrypted/decrypted 
   fileID=fopen(filename);
   input_text=fread(fileID)';
   fclose(fileID);
   % throw away all entries  excepts letters and spaces and periods
   % convert all letters to uppercase
   counter=0;
   for k=1:length(input_text)
       letter=input_text(k);
       if letter ==32
           counter=counter+1;
           plain_text(counter)=26;
       elseif (65<=letter)&&(letter<=90)
           counter=counter+1;
           plain_text(counter)=letter-65;
       elseif (97<=letter)&&(letter<=122)
           counter=counter+1;
           plain_text(counter)=letter-97;
       end        
   end 
   % show the modified text
   char(plain_text+65)
   % create new_text with shifted letters
   new_text = plain_text;
   rng('default');
   rng(seed);
   %for k=1:length(new_text)
   for k=1:length(new_text)
       letter=new_text(k);
       if   (0 <= letter)&&(letter <= 26)
           shift=randi(27); 
           new_text(k) = mod(shift+letter,27);
           ss(k)=shift;
       end % end if
   end % for k
   % save first 2000 letters encrypted text to a file
   % use same name, but add '.rs2' to end
   out=char(new_text+65)
   out_filename=[filename,'.rs2'];
   fileID=fopen(out_filename,'w+');
   fwrite(fileID,out);
   fclose(fileID);
return
