% 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 rs(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
% 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)=letter;
if (65<=letter)&&(letter<=90)
counter=counter+1;
plain_text(counter)=letter;
elseif (97<=letter)&&(letter<=122)
counter=counter+1;
plain_text(counter)=letter-32;
end
end
% show the modified text
char(plain_text)

% create new_text with shifted letters
new_text = plain_text;
rng('default');
rng(seed);
for k=1:length(new_text)
letter=new_text(k);
if (65 <= letter)&&(letter <= 90)
new_text(k) = 65+mod(randi(26)+letter-65,26);
end % end if
end % for k
% save encrypted text to a file
% use same name, but add '.caesar' to end
out=char(new_text)
out_filename=[filename,'.rs'];
fileID=fopen(out_filename,'w+');
fwrite(fileID,out);
fclose(fileID);
return