PassWord Generatro

by

 

PassWord Generator for MatLab

Pass=PassWord(n,N,lowCase,UpperCase)
%Alex Dytso
% 06-04-2012
% Description: This code generates passwords of length n with specified
% number of digits, lowercase letters and upper case letters. It also uses
% famous  Knuth alogorithm for shuffling 

function Pass=PassWord(n,N,lowCase,UpperCase)

%n --length of the password
%N --How many digits
%lowCase-- number of many lower case letters
%UpperCase-- number of upper case letters

if n~=N+lowCase+UpperCase
    
    error('Number of symbols is mismatched')
end


if n==N% if password is only numeric
    
    Pass=floor(10*rand(1,n));% generating random digits

else
    
    Nlow=floor(26*rand(1,lowCase));% there are 26 letters in English alphabet. This code randomly picks  lower case letters
    
    Nup=floor(26*rand(1,UpperCase));% there are 26 letters in English alphabet. This code randomly picks  upper case letters
    
    lowLet=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
    
    upperLet=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] ;
    
    
    
    PassLow=lowLet(Nlow); % selects randomly picked lowercase letters
    
    PassHigh=upperLet(Nup); % selects randomly picked lowercase letters
   
    
    PassNumbers=floor(10*rand(1,N));% generating random digits
    
    PassNumbers=num2str(PassNumbers);% convertingt to strings
    
    PassV=[PassLow,PassHigh,PassNumbers];
    
   
    
    % Shuffling. Shuffling usess famous Knuth alogorithm
    
    j=length(PassV);
    index=1:j;
    
    while j>=1
          R=ceil(j*rand);% creating random index
          
          temp=index(j);% temporary storage 
          
          index(j)=index(R);% exchanging
          
          index(R)=temp;% exchanging 
          
          j=j-1;
        
    end
        
        Pass=PassV(index); %output Password
        
end

end
    
    

Contact us