% creates an example reuse of one time pad by
% reading in a file and two starting postiions
% and then subtracting the corresponding strings
% modulo 27

function make_twice(filename,n1,n2)
% 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)=91;
elseif (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
% choose two texts
text1=plain_text(n1:n1+1000)
text2=plain_text(n2:n2+1000)
% create new_text with shifted letters
new_text = text1;
for k=1:length(new_text)
letter=new_text(k);
new_text(k) = 65+mod(-(text2(k)-65)+text1(k)-65,27);
end % for k
% save encrypted text to a file
% use same name, but add '.caesar' to end
out=[char(new_text),text1,text2]
fileID=fopen('twice.txt','w+');
fwrite(fileID,out);
fclose(fileID);
return