If you want to write out every possible word for every length from 1 up, use this:
program New;
const
T = 'abcdefghijklmnopqrstuvwxyz'; //the characters to use
chars = 1;
var
I, curPos, maxPos, maxChar, L, Time: Integer;
curChar: Array of Integer;
msgOrds, tOrds, mods: Array of Byte;
tmpMsg: String;
begin
Time:= GetSystemTime;
maxChar:= Length(T);
maxPos:= chars;
SetLength(curChar, 10);
SetLength(tmpMsg, chars);
SetLength(tOrds, Length(T) + 1);
for I:= 1 to Length(T) do
tOrds[i]:= ord(T[i]);
SetLength(mods, L + 1);
repeat
if(curPos < maxPos)then
begin
inc(curPos);
for I:= 1 to L do
Mods[i]:= (I - 1) mod curPos + 1;
end;
if(curChar[curPos] < maxChar)then
inc(curChar[curPos])
else begin
curChar[curPos]:= 0;
if(curPos = 1)then
begin
SetLength(tmpMsg, Length(tmpMsg) + 1);
inc(maxPos);
end;
curPos:= max(0, curPos - 2);
continue;
end;
tmpMsg[curPos]:= chr(tOrds[curChar[curPos]]);
writeln(tmpMsg);
until(False);
end.
If you just want to set a length and get the words for that length, use this:
program New;
const
T = 'abcdefghijklmnopqrstuvwxyz'; //the characters to use
chars = 3; //how many characters
var
I, curPos, maxPos, maxChar, L, Time: Integer;
curChar: Array of Integer;
msgOrds, tOrds, mods: Array of Byte;
tmpMsg: String;
begin
Time:= GetSystemTime;
maxChar:= Length(T);
maxPos:= chars;
SetLength(curChar, 10);
SetLength(tmpMsg, chars);
SetLength(tOrds, Length(T) + 1);
for I:= 1 to Length(T) do
tOrds[i]:= ord(T[i]);
SetLength(mods, L + 1);
repeat
if(curPos < maxPos)then
begin
inc(curPos);
for I:= 1 to L do
Mods[i]:= (I - 1) mod curPos + 1;
end;
if(curChar[curPos] < maxChar)then
inc(curChar[curPos])
else begin
for I:= 1 to maxPos do
if(tmpMsg[I] <> T[Length(T)])then
break;
if(I = maxPos + 1)then exit;
curChar[curPos]:= 0;
curPos:= max(0, curPos - 2);
continue;
end;
tmpMsg[curPos]:= chr(tOrds[curChar[curPos]]);
writeln(tmpMsg);
until(False);
end.
Please don't mind the actual code… I modified my bruteforcer for mixster's encryption competition.