Autor Beitrag
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mo 21.02.05 17:22 
Hallo,ich bin einen Passwordmanager am proggen, und dachte ich muss meine Passwörter dann ja auch verschlüsseln, deshalb habe ich einmal einen blick in mein Delphibuch geworfen, und siehe da ich habe diesen Code hier gefunden:
ausblenden 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:
procedure TForm1.FormCreate(Sender: TObject);
var i : Integer;
begin
randseed := code; Randomize;
for i  := 1 to high(superkey) do superkey[i]:=random(255); 
end;

procedure TForml.ButtonlClick(Sender: TObject); 
var
s : string[255];
c : array[0..255] of byte absolute s;
i : Integer;
begin
If Buttonl.Caption - 'Codieren' Then begin
s := Memol.Text;
For i  := 1 To 0rd(s[0]) do c[i]  := superkey[i] Xor c[i];
Buttonl.Caption := 'Decodieren1;
Labell.Caption := s; end eise begin
s := Labell.Caption;
For i  := 1 To Length(s) do s[i]  := Chr(superkey[i] Xor ord(s[i]));
buttonl.Caption := '
Codieren';
memol.Text := s;
labell.Caption := " 
end 
end;

Nur werde ich nicht besonders schlau daraus, weil nicht alle variabeln deklariert werden. Kann mir jemand helfen?
Invulnerabilis
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 21.02.05 17:39 
Woher hast du denn das!??

Hast es gescannt? "L"="I"="1"...

1.
Sehr merkwürdig programmiert mit dem
s : string[255];
c : array[0..255] of byte absolute s;
und später wird trotzdem mit ord(s[i]) drauf zugegriffen?
Es wäre ja sowieso "c : array[0..256] of byte absolute s;". Aber du kannst dir das sparen, denn: c[...] = ord(s[...]) = byte(s[...])

2.
ord(s[0]) ist veraltet (macht auch semantisch wenig Sinn). Man sollte length(s) schreiben.

3.
Dein "Randomize;" macht dein "randseed := code;" kaputt.

Naja, hier ist's auf jeden Fall korrigiert:

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:
const
 code = 3;
var
 superkey : array[0..255] of byte;

procedure TForm1.FormCreate(Sender: TObject);
var i : Integer;
begin
 randSeed := code;
 Button1.Caption := 'Codieren';
 for i  := 0 to high(superkey) do
  superkey[i] := random(256);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 s : string;
 i : Integer;
begin
 If Button1.Caption = 'Codieren' then
 begin
  s := Memo1.Text;
  for i := 1 to length(s) do
   s[i] := char(superkey[(i-1) mod length(superkey)] xor byte(s[i]));
  Button1.Caption := 'Decodieren';
  Label1.Caption := s;
  Memo1.Text := '';
 end else
 begin
  s := Label1.Caption;
  For i := 1 to length(s) do
   s[i] := char(superkey[(i-1) mod length(superkey)] xor byte(s[i]));
  Button1.Caption := 'Codieren';
  Memo1.Text := s;
  label1.Caption := '';
 end;
end;


// Edit: hab noch das mod noch ins superkey[] reingetan, um überläufe zu verhindern.


Zuletzt bearbeitet von delfiphan am Mo 21.02.05 17:52, insgesamt 2-mal bearbeitet
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mo 21.02.05 17:45 
Danke, und kann wie kann ich byte zu string konvertieren(ähnlich wie inttostr)?
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 21.02.05 17:53 
ein byte in einen string? mit inttostr...
gruss
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mo 21.02.05 18:12 
Danke