%for 4 character alphabet
%to generate histograms and scatterplots for indicated hash model
%(analyzing models that just produce 1 character in hash output)
function[mstr]=master(file,L,l,t,ring,level)%input file-document (with different ascii character frequencies),L-# of characters in message,l-# of messages plotted in each plot,t-# that corresponds to hashing method,ring-ringlength (#),level-#of layers in petri-dish
M= dlmread(file,':');
p=M(:,2);%probability each character occurs in file (in order of ascii alphabet - for possible characters in file)
k=(1/4)+zeros(1,4);%equal probability of getting any character in the 4 character ascii alphabet for key
ascii1=char(reshape(32:126,95,1)');%define ascii1 alphabet as only printable characters
ascii2=char(reshape(0:127,128,1)');%define ascii2 alphabet as all ascii characters
new=[];%to initialize probability vector of characters occuring in file
newkey=[];%to initialize probability vector of each key character occuring
new(1)=p(1);
newkey(1)=k(1);
slink=(1/L)+zeros(1,L);%equal probability vector of choosing a spot in original message to change 
newslink=[];%to initialize probability vector of which character should be changed in each message
newslink(1)=slink(1);
newchars=[];%to initialize probability vector of what character the changed spot will change to
newchars(1)=p(1);
%for all probabilities after 1st probability of each probability vector,
%change each probability to its sum with all values to it's right
for i=2:length(p); %for character generation probability vector
    new(i)=p(i)+new(i-1); 
end;
for v=2:length(k);%for key character generation probability vector
    newkey(v)=k(v)+newkey(v-1);
end;
for w=2:length(slink);%for changed spot probability vector
    newslink(w)=slink(w)+newslink(w-1);
end;
for a=2:length(p);%for character of changed spot probability vector
    newchars(a)=p(a)+newchars(a-1);
end;
hash=[];
lofmessages=[];
lofkeys=[];
%using random number generator (randomly choose) characters for each
%orignial message
for m=1:l;
    for j=1:L;
        ref=rand;
        ind=(ref>=new);
        num(j)=sum(ind)+1;
        message=ascii1(num);
    end;
    %using random number generator (randomly choose) characters for each key
    key=rand;
    indy=(key>=new);
    keyused=ascii1(sum(indy)+1);
    %using random number generator (randomly choose) spot to change
    %character from original message
    spo=rand;
    indie=(spo>=newslink);
    spot=sum(indie)+1;
    %using random generator (randomly choose) character that changed spot
    %will changed to
    let=rand;
    inni=(let>=newchars);
    letter=sum(inni)+1;
    num(spot)=letter;
    messy=ascii1(num);
    lofmessages=[lofmessages;message];
    lofkeys=[lofkeys;keyused];
       %to compute hash output of orignal message (hash) and changed message
       %(hash2)
        if t==1 %to test split model (assuming alphabet out of all 128 ascii characters) 
            hash(m,t)=ultsplit(message,keyused);
            hash2(m,t)=ultsplit(messy,keyused);
       elseif t==2%to test spoke model (assuming alphabet always starts with first character in ascii alphabet)
            hash(m,t)=ultspoke(message,keyused,128,1);
            hash2(m,t)=ultspoke(messy,keyused,128,1);
       elseif t == 3%to test andorsplitmodel (assuming alphabet out of all 128 ascii characters)
            hash(m,t)= andorsplitmodel(message,keyused);
            hash2(m,t)=andorsplitmodel(messy,keyused);
       elseif t == 4%to test fixnet model
           hash(m,t)=fixnet(message,128,0,56,1,7);
           hash2(m,t)=fixnet(messy,128,0,56,1,7);
       elseif t == 5%to test split model (not assuming alphabet out of 128 ascii character alphabet)
           hash(m,t)=ultsplit2(message,keyused,8,65);
           hash2(m,t)=ultsplit2(messy,keyused,8,65);
       elseif t == 6%to test spoke model (flexability with what character alphabet starts with)
           hash(m,t)=ultspoke2(message,keyused,8,65,1);
           hash2(m,t)=ultspoke2(messy,keyused,8,65,1);
       elseif t==7%to test neteyesmodel
           hash(m,t)=netyes1(message,128,0,ring,1,level);
           hash2(m,t)=netyes1(messy,128,0,ring,1,level);
       elseif t==8 %to test twist model
           hash(m,t)=twist(message,4,65,ring,1,level);
           hash2(m,t)=twist(messy,4,65,ring,1,level);
        else %to test netpad model
           hash(m,t)=netpad(message,8,65,112,1,3);
           hash2(m,t)=netpad(messy,8,65,112,1,3);
       end;
end;
x=[];
y=[];
%to extablish that hash value of orignial message plotted on x axis and
%hash value of changed message plotted on y axis
for k=t:t;
 for i=1:l;
    val(i)=hash(i,t);
    val2(i)=hash2(i,t);
 end;
x=val;
y=val2;
z= 0:127;
figure
scatter(x,y);
title('Scatter Plot of Message Hash vs. Altered Message Hash')
ylabel('AlteredMessage Hash')
xlabel('Message Hash')
c=corrcoef(x,y) %to calculate correlation coefficient between all hash values of original messages verses changed messages
%to generate histogram of how often hash values occuring with various
%messages
figure
hist(x,z);
h = findobj(gca, 'Type','patch');
set(h,'FaceColor','r','EdgeColor','w')
title('Hash Value Distribution')
xlabel('Hash Values in Decimal')
ylabel('Number of Hashes')
end;