Autor Beitrag
Sauger Chris
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Di 10.04.07 15:44 
Hallo

so hier mein prob. (auch wen die lösung so einfach is)
ich komm gerade nicht drauf *heul

Frage: wie müßte der code aus sehen wen ich das ganze mit ner tstringlist machen würde

code bis jetzt (string)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function crypte(text:string):string;
var
  i: Integer;
begin
  for i:=1 to length(text) do
    text[i]:=char(23 Xor Ord(text[i]));
    result := text;
    end;

aufrufen: crypte.text := crypte(klartext.text);


ps. is ne ganz normale xor verschlüßelung

will das ganze nacher so umbauen das ich ne kleine consolen anwendung hab

application.exe -crypte test.txt

danke

sauger chris
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 10.04.07 15:46 
Moin!

Die entscheidende Frage: sollen die Zeilenumbrüche in der Liste erhalten bleiben oder nicht?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Di 10.04.07 15:52 
jo solte nacher beim entschlüßeln genau so ausgegeben werden wie zum anfang :)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 10.04.07 15:57 
Moin!

Sorry, aber du hast meine Frage nicht beantwortet: Sollen die Zeilenumbrüche im verschlüsselten Text erhalten bleiben oder nicht? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Di 10.04.07 16:08 
ja die Zeilenumbrüche sollen in text erhalten bleiben
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 10.04.07 16:09 
Moin!

Dann probier das mal so: ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  SL: TStringList;
  i: Integer;

begin
  for i := 0 to SL.Count-1 do
    SL.Strings[i] := Crypt(SL.Strings[i]);

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Di 10.04.07 16:41 
ok geht ich bedanke mich
wußte doch das das so einfach war ^^

hier mal das ganze mit ner consolen anwendung =) (fals es einen interessiert :)

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:
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;

function decrypte(text:String):String;
var i:integer;
begin
for i:=1 to length(text) do
    text[i]:=char(23 Xor ord(text[i]));
  result :=text;
  end;

function crypte(text:String):String;
var
  i: Integer;
begin
  for i:=1 to length(text) do
    text[i]:=char(23 Xor Ord(text[i]));
    result := text;
    end;

var  sl: TStringList;
     a : integer;

begin
sl := TStringList.Create;
try
if ParamStr(1) = '-crypte' then
begin
sl.LoadFromFile(ParamStr(2));
for a := 0 to SL.Count-1 do
    SL.Strings[a] := crypte(SL.Strings[a]);
sl.SaveToFile('crypte.txt');
end;

if ParamStr(1) = '-decrypte' then
begin
sl.LoadFromFile(ParamStr(2));
for a := 0 to SL.Count-1 do
    SL.Strings[a] := decrypte(SL.Strings[a]);
sl.SaveToFile('encrypt.txt');
end;
    finally
     sl.free;
    end;
end.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 10.04.07 16:48 
Moin!

Habe mir soetwa den Code von dir vorgestellt... ;)

Es gibt da allerdings ein Problem: wenn bei deiner Verschlüsselung Zeichencodes unterhalb #32 entstehen, dann wird es möglicherweise zu Problemen mit dem .LoadFromFile kommen, was in fehlerhaften oder zumindest falsch interpretierten Zeilenumbrüchen kommen. Das kannst du nur dadurch vermeiden, dass du den verschlüsselten Text als Stream speicherst und dann auch wieder lädst. Das mit dem TStringList.LoadFromFile/.SaveToFile ist (sogesehen leider, aber anders geht´s eben nicht) nur für Textdateien machbar. :mahn: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Di 10.04.07 16:53 
passt schon so ;-)

danke noch mal