I'm working on a project in MATLAB that aims to break a user-inputted password using brute force. I've successfully set it up to break passwords up to eight characters in length, but I want it to be able to work for passwords of any length. As it stands, the code basically checks all possible one character passwords, then all possible two character passwords, etc. (Note: realpass is the user-inputted password, guess is the computer-generated guess, alphasize is the length of the alphabet of characters I give MATLAB to check at the start of the script, i.e., the number of possible characters.)
% check all 1 character passwords possible w/ given alphabet
if strcmp(guess, realpass) == 0
for i = 1:alphasize(2)
guess(1) = alphabet(i);
if strcmp(guess, realpass) == 1
break
end
end
end
% the password has more than one characters, check all possible 2 character passwords
if strcmp(guess, realpass) == 0
for i = 1:alphasize(2)
guess(1) = alphabet(i);
for j = 1:alphasize(2)
guess(2) = alphabet(j);
if strcmp(guess, realpass) == 1
break
end
end
if strcmp(guess, realpass) == 1
break
end
end
end
As you could probably tell, to get this out to 8 characters, there's a lot of copy/pasting, which is an excellent indicator that a loop can be used. My trouble is getting the loop to behave right. You can see my attempt on github. Does anyone have any advice for getting this thing up and running?
Thanks so much!