Autor Beitrag
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 04.06.05 10:12 
Diese Funktion hier ist ewas zu lang(sam). Kann man die irgendwie optimieren?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
function RandomPassword(Last: String): String;
var
  Laenge, Zahl, Schleife, Minus: Integer;
  NBuch, LBuch: String;
begin
  Result := '';
  Laenge := Length(Last)-1;
  LBuch := Copy(Last, Laenge+11);
  Zahl := 0;
  Minus := 1;

  for Schleife := 97 to 121 do
  begin
    if BArray[Schleife] = LBuch then
    begin
      Zahl := Schleife;
      Break;
    end;
  end;

  if (Zahl = 0AND (Copy(Last, 01) <> 'z'then
  begin
    LBuch := Copy(Last, Laenge, 1);

    for Schleife := 97 to 121 do
    begin
      if BArray[Schleife] = LBuch then
      begin
        Zahl := Schleife;
        Break;
      end;
    end;

    while Zahl = 0 do
    begin
      LBuch := Copy(Last, Laenge-Minus, 1);

      for Schleife := 97 to 121 do
      begin
        if BArray[Schleife] = LBuch then
        begin
          Zahl := Schleife;
          Break;
        end;
      end;

      inc(Minus);
    end;

    NBuch := Chr(Zahl+1);

    for Schleife := 1 to Minus do
      NBuch := NBuch + 'a';

    Result := Copy(Last, 0, Laenge-Minus) + NBuch;
  end
  else
  begin
    NBuch := Chr(Zahl+1);

    if (Copy(Last, 01) = 'z'AND (Zahl = 0then
    begin
      NBuch := 'a';

      for Schleife := 1 to Laenge+1 do
        NBuch := NBuch + 'a';

      Result := NBuch;
    end
    else
      Result := Copy(Last, 0, Laenge) + NBuch;
  end;
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
GTA-Place Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 04.06.05 18:23 
Hab den Source mal mit Hilfe von Kroni optimiert:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
function RandomPassword(Last: String): String;
var
  Laenge, Zahl, Schleife, Minus, TempInt: Integer;
  LBuch, TempS: String;
begin
  Result := '';
  Laenge := Length(Last)-1;
  LBuch := Last[Laenge + 1];
  Minus := 1;
  TempInt := 97;

  while (TempInt < 122AND (BArray[TempInt] <> LBuch) do
    inc(TempInt);

  Zahl := TempInt;
  TempInt := 97;

  if (Zahl = 122AND (Last[1] <> 'z'then
  begin
    LBuch := Last[Laenge];

    while (TempInt < 122AND (BArray[TempInt] <> LBuch) do
      inc(TempInt);

    Zahl := TempInt;
    TempInt := 97;

    while Zahl = 122 do
    begin
      LBuch := Last[Laenge - Minus];

      while (TempInt < 122AND (BArray[TempInt] <> LBuch) do
        inc(TempInt);

      Zahl := TempInt;
      TempInt := 97;

      inc(Minus);
    end;

    Result := Chr(Zahl+1);

    for Schleife := 1 to Minus do
      Result := Result + 'a';

    TempS := '';

    for Schleife := 1 to Laenge - Minus do
      TempS := TempS + Last[Schleife];

    Result := TempS + Result;
  end
  else
  begin
    Result := Chr(Zahl+1);

    if (Zahl = 122AND (Last[1] = 'z'then
    begin
      Result := 'a';

      for Schleife := 1 to Laenge + 1 do
        Result := Result + 'a';
    end
    else
    begin
      TempS := '';

      for Schleife := 1 to Laenge do
        TempS := TempS + Last[Schleife];

      Result := TempS + Result;
    end;
  end;
end;


Er hat mich darauf hingewießen, dass copy(); langsam ist. Thx.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)