Nevermind, I'm done with it. It was the stupidest error ever.
In the for cycle when I'm writing the results out
Instead of Results[Num] I should use Results[j]
Now the code is fully functional(except for that it takes forever to decode anything beyond 4 character length) Thanks for the input guys.
Code:
Program Md5BruteForce;
Uses Md5;
Var
hash,test,tri:string;
Num,Max,j:integer;
Results:array[1..100] of string;
Function NextChar(c:char):char; //This is for changing the characters in the string
Begin
if c='z' then NextChar:='0'
else
if c='9' then NextChar:='a'
else
NextChar:=Succ(c); //Succ=Next Character in ABC order, next number if the character is a number
End;
Procedure ChangeChar(MaxLength,spot:integer; Var Str:string); //The main procedure
Var
counter:integer;
i:integer;
Begin
counter:=0;
if Str[spot]='9' then
begin
if length(Str)<=MaxLength then
begin
for i:=1 to length(Str) do
begin
if Str[i]='9' then counter:=counter+1; //Count the 9s in the string
end;
if counter=length(Str) then
begin
for i:=1 to length(Str) do Str[i]:='a';
Str:=Str+'a'; //If every character is a 9, then change all of them back to 'a', and add a plus 'a' to the string
end
else
begin
Str[spot]:='a';
ChangeChar(MaxLength, spot-1,Str); //The procedure calls itself, until a non-9 character is found
end;
end;
end
else
Str[spot]:=NextChar(Str[spot]); //If a non-9 character is found then it is simply switched to the next character
End;
Begin
for j:=1 to 100 do
begin
Results[j]:=''; //Clearing the array, just to make sure...
end;
Writeln('Please Give me the hash');
Readln(hash);
Writeln('Please give me the estimated maximum length of the original text(characters)');
Readln(Max);
test:='a';
Num:=1;
Repeat
tri:=MD5Print(Md5String(test));
if tri=hash then
begin
Results[Num]:=test;
Num:=Num+1; //Storing the matches in an array
end;
Write('Now trying: ',test);
Write(' ');
Writeln('Hash: ',tri); //A bit redundant, but it helped me debug the recursion, and it looks cool so I kept it.
ChangeChar(Max,length(test),test); //Go to the next variation
Until length(test)>Max; //Loop ends if the maximum character length is exceeded
if Num>1 then //Checking if there is more than 0 results
begin
for j:=1 to Num-1 do
begin
Writeln('Result #',j,': ',Results[j]); //Writing out all the results
end;
end
else
Writeln('Sorry, your hash could not be recovered'); //If the search fails...
Readln;
End.
Bookmarks