10月 032012
 

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Math, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure MakePass;
public
{ Public declarations }
end;

var
Form1: TForm1;
const
StartLEn = 1;
Endlen = 3;
srcDictString = ‘abcd’;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.MakePass;
var
nRect: Integer;
nCount: Integer;
nTotal: Double;
I, J, K: Integer;
nIndex: array of Integer;
chPass: array of char;
strTemp: string;
begin
nCount := Length(srcDictString);
for I := StartLEn to Endlen do begin
nTotal := Power(nCount, I);
SetLength(nIndex, I);
SetLength(chPass, I);
for J := 0 to Trunc(nTotal) – 1 do begin
for K := 0 to I – 1 do begin
if (nIndex[K] = nCount) then begin
nIndex[K] := 0;
if K < I – 1 then
nIndex[K + 1] := nIndex[K + 1] + 1;
end;
end;

for K := 0 to I – 1 do begin
chPass[I – K – 1] := srcDictString[nIndex[K] + 1];
end;

nIndex[0] := nIndex[0] + 1;
strtemp := string(@chPass[0]);
Memo1.Lines.Add(strTemp);
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
MakePass;
end;

end.

打赏