%to generate scatter plots for either the split or spoke model, key can
%only be out of 95 printable characters
function[rmg]=randgen(file,L,l,T)%input file-document (with different ascii character frequencies),L-# of characters in message,l-# of messages plotted in each plot, T-# based on spoke or split model
M= dlmread(file,':');
p=M(:,2);%probability each character occurs in file (in order of ascii alphabet - for possible characters in file)
k=(1/95)+zeros(1,95);%equal probability of getting any character of printable ascii alphabet for key
ascii=char(reshape(32:126,95,1)');%define ascii alphabet as only printable 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=[];
%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=ascii(num);  
    end;
    %using random number generator (randomly choose) characters for each key
    key=rand;
    indy=(key>=newkey);
    keyused=ascii(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=ascii(num);
    %to compute hash output of orignal message (hash) and changed message
       %(hash2)
   for t=1:2;
        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);
        end;
        if 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);
        end;
   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 t=1:2;
for i=1:l;
    val(i)=hash(i,t);
    val2(i)=hash2(i,t);
end;
x=val;
y=val2;
figure
scatter(x,y);
title('Scatter Plot of Message Hash vs. AlteredMessage 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
end;