Autor Beitrag
AScomp
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 162


Delphi 5, Delphi 7, Delphi 2007, Delphi 2009, Delphi XE, Delphi 10 Seattle
BeitragVerfasst: Do 11.12.08 14:24 
Hallo zusammen,

nachfolgende Funktion möchte ich unter Delphi 2009 kompilieren:

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:
75:
76:
77:
function PassphraseQuality(const Password: String): Extended;
  function Entropy(P: PByteArray; L: Integer): Extended;
  var
     Freq: Extended;
     I: Integer;
     Accu: array[Byte] of LongWord;
  begin
       Result := 0.0;
       if L <= 0 then
          Exit;
       FillChar(Accu, SizeOf(Accu), 0);
       for I := 0 to L-1 do
           Inc(Accu[P[I]]);
       for I := 0 to 255 do begin
           if Accu[I] <> 0 then begin
              Freq := Accu[I] / L;
              Result := Result - Freq * (Ln(Freq) / Ln(2));
           end;
       end;
  end;

  function Differency: Extended; 
  var
     S: String;
     L,I: Integer;
  begin 
       Result := 0.0;
       L := Length(Password);
       if L <= 1 then
          Exit;
       SetLength(S, L-1);
       for I := 2 to L do
           Byte(S[I-1]) := Byte(Password[I-1]) - Byte(Password[I]);
       Result := Entropy(Pointer(S), Length(S));
  end

  function KeyDiff: Extended; 
  const
        Table = '^1234567890ß´qwertzuiopü+asdfghjklöä#<yxcvbnm,.-°!"§$%&/()=?`QWERTZUIOPÜ*ASDFGHJKLÖÄ''>YXCVBNM;:_';
  var
     S: String;
     L,I,J: Integer;
  begin 
       Result := 0.0;
       L := Length(Password);
       if L <= 1 then
          Exit;
       S := Password;
       UniqueString(S);
       for I := 1 to L do begin
           J := Pos(S[I], Table);
           if J > 0 then
              S[I] := Char(J);
       end;
       for I := 2 to L do
           Byte(S[I-1]) := Byte(S[I-1]) - Byte(S[I]);
       Result := Entropy(Pointer(S), L-1);
  end;

const
     GoodLength = 10.0// good length of Passphrases
var
   L: Extended;
begin
     Result := Entropy(Pointer(Password), Length(Password));
     if Result <> 0 then begin
        Result := Result * (Ln(Length(Password)) / Ln(GoodLength));
        L := KeyDiff + Differency;
        if L <> 0 then
           L := L / 64;
        Result := Result * L;
        if Result < 0 then
           Result := -Result;
        if Result > 1 then
           Result := 1;
     end;
end;



Probleme hierbei machen die Zeilen

Byte(S[I-1]) := Byte(Password[I-1]) - Byte(Password[I]);

und

Byte(S[I-1]) := Byte(S[I-1]) - Byte(S[I]);

in den Funktionen Differency und KeyDiff.

Compiler-Meldung:
[DCC Fehler] UnitMain.pas(827): E2064 Der linken Seite kann nichts zugewiesen werden

Hat mir jemand einen Tipp, wie man das jetzt in Delphi 2009 zum Laufen bekommt?

Danke schonmal!

Viele Grüße,

Andy
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 11.12.08 14:28 
Evtl. genügt es bereits, wenn Du alle Strings als AnsiStrings deklarierst. Leider habe ich kein D2009, um das auszuprobieren.
AScomp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 162


Delphi 5, Delphi 7, Delphi 2007, Delphi 2009, Delphi XE, Delphi 10 Seattle
BeitragVerfasst: Do 11.12.08 14:36 
Das würde zwar schon helfen, bringt mir aber nichts - ich möchte schon Unicode unterstützen.

Hat sonst noch jemand einen Tipp?
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 11.12.08 14:37 
Ord() wird bei Unicode vermutlich auch nicht gehen, oder?
AScomp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 162


Delphi 5, Delphi 7, Delphi 2007, Delphi 2009, Delphi XE, Delphi 10 Seattle
BeitragVerfasst: Do 11.12.08 14:40 
Nein, dasselbe Problem leider.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 11.12.08 14:58 
Wenn du Unicode unterstützen willst, dann wirst du das mehr oder weniger neu schreiben müssen. Jedes Zeichen ist eben nicht vom Typ Byte und auch nicht als solches behandelbar. Es ist vom Typ Char und der hat 2 Byte. Dementsprechend musst du das dann ändern.
Manina
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44

Win 7 Pro
RAD Studio 2010 Pro
BeitragVerfasst: Do 11.12.08 15:11 
evtl. stört ja nur das casting ?
Geht denn sowas unter D2009 ?

ausblenden Delphi-Quelltext
1:
    s[i-1] := Char(Byte(s[i-1]) - Byte(s[i]));					

_________________
Gates, oder Gates nicht ?
AScomp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 162


Delphi 5, Delphi 7, Delphi 2007, Delphi 2009, Delphi XE, Delphi 10 Seattle
BeitragVerfasst: Do 11.12.08 15:26 
Nein, das ist leider auch nicht möglich.

Egal, ich nutze es erst mal doch nur als Ansi-Version. Trotzdem danke für eure Tipps!