Autor Beitrag
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Do 15.04.04 08:36 
Hallo,
habe ein problem mit einem array und dem 0 index das ist richtig seltsamm:
ich habe eine verschlüsselungs-funktion geschrieben wo ich ein zuffalls array(0-255) of byte groß ist habe nun habe ich das problem sobalt ein zeichen den wert 0 hat schreibt er dieses zeichen nicht mehr.

leider habe ich z.z. den qullcode nicht zur hand, der kommt später.......

_________________
MFG
Michael Springwald, "kann kein englisch...."
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Do 15.04.04 11:12 
Wenn ich das richtig verstanden habe, ist das Problem, dass er #0 (oder alles dahinter) nicht mehr ausgibt? Das liegt daran, dass #0 das Zeichen ist, das angibt, dass ein PChar (string nicht, aber pchar wird eben überall in Windows benutzt) zuende ist.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 16.04.04 08:37 
ich habe das problem jetzt vertstanden kann es aber nicht behben:
das problem liegt daran das der 0 wert vom array eine #0 ist, warum ???
der 1 wert ist das nicht....
ich arbeitet mit byte und integer und strings.... ich nutzte die funktion chr sobalt die diesen wert bekommt, gibt sie wie gesagt eine #0 zurück.... wenn ich die funktion weglasse,gibt sie mir eine normale 0 zurück warum ????

_________________
MFG
Michael Springwald, "kann kein englisch...."
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 16.04.04 08:41 
Zeig am besten Code. So versteht dich wohl niemand so richtig.
bms
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 735

Win XP
Delphi 3, Delphi 6 PE, Delphi 2005 PE
BeitragVerfasst: Fr 16.04.04 08:47 
Ich kenne dein Algo nicht, aber 1 x 5 ist 5, 2 x 5 ist 10 und 0 x 5 ist 0. Es kann sein, daß die 0 kein anderes Ergebnis liefen kann.

_________________
VORSICHT: Ich behersche seit heute die Fünf-Finger-Handflächen-Herz-Explodier-Schlag-Kampf-Technik >:(
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 17.04.04 18:05 
hier währe der code....
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:
Procedure CreateRandomValues(var a:Array of byte); 
Var i,v,index1,index2:byte;
Begin 
  For i:=0 to High(a) do a[i]:=i; //Werte vorbelegen;

  For i:=0 to 255 do Begin
    index1:=Random(Length(a));
    index2:=Random(Length(a));
    v:=a[index1];
    a[index1]:=a[index2];
    a[index2]:=v;
  End;

End;

function GetArrayIndex(wert:Integer; ascci:array of Byte): Integer;
var
  i:byte;
begin
  result:=-1;
  for i:=0 to High(ascci) do begin
    if ascci[i] = wert then begin
      result:=i;
      exit;
    end;  
  end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  ascci:array[0..255] of Byte;
  i:Integer;
begin
  Edit2.Text:='';
  RandSeed:=StrToInt(Edit3.Text);
  CreateRandomValues(ascci);

  for i:=0 to Length(Edit1.Text) do begin
    Edit2.Text:=Edit2.Text + chr( ascci[ ord(Edit1.Text[i+1]) ] );
  end;

 // ArrayToFile(ascci);
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
  ascci:array[0..255] of Byte;
  i:Integer;
begin
  Edit4.Text:='';

  RandSeed:=StrToInt(Edit3.Text);
  CreateRandomValues(ascci);

  for i:=0 to Length(Edit2.Text)-1 do begin
    Edit4.Text:=Edit4.Text + CHR( GetArrayIndex(ord(edit2.text[i+1]),ascci)  );
  end;
end;

_________________
MFG
Michael Springwald, "kann kein englisch...."
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 17.04.04 20:13 
das problem liegt bei den zahlen, sobalt ich chr(4) aufrufe bekomme ich eine #4 zurück
wie kann ich das umwandeln also das chr(ord(ascci[i])); geht ???

_________________
MFG
Michael Springwald, "kann kein englisch...."
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 18.04.04 08:36 
das problem ist nicht mit chr, sondern mit ord ..... wenn ich ord('1') aufrufe wird die richtige zahl raußgegeben, aber sonst nicht. wie kann ich es richtig umwandeln so das das auch mit zahlen funktionirt ???

_________________
MFG
Michael Springwald, "kann kein englisch...."