Autor Beitrag
blaskito
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Win2003, 2008, 2012, WinXP, Win7
Delphi 6 Pers.
BeitragVerfasst: Fr 17.07.09 11:17 
Hallo,

ich habe mal eine ganz einfache Verschlüsselung ausgeknobelt, die ich für das Speichern z.B. von Kennwörtern in INI-Dateien verwende. Ich würde gerne mal hören, was die Community dazu sagt:

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:
function EncodeString(TextString, pwd: string):string;
var
  Zeile,pwdZeile:string;
  i,Anzahl,Zahl,Zufall,pwdZahl:Integer;
begin
  Result:='';
  if TextString='' then Exit;
  pwdZahl:=GetCheckSum(pwd);
  Randomize;
  Zufall:=Random(223)+32;
  pwdZeile:='';
  Result:='';
  Anzahl:=Length(TextString);
  while Length(pwdZeile)<Anzahl do pwdZeile:=pwdZeile+pwd;
  for i:=1 to Anzahl do begin
    Zahl:=Ord(TextString[i])+Ord(pwdZeile[i])+pwdZahl;
    while Zahl>255 do Zahl:=Zahl-223;
    Zeile:=Zeile+Chr(Zahl);
  end;
  Zeile:=Zeile+Chr(Zufall);
  pwdZeile:=pwdZeile+pwd;
  Anzahl:=Length(Zeile)-1;
  for i:=Anzahl downto 1 do begin
    Zahl:=Ord(Zeile[i])+Ord(pwdZeile[i])+Ord(Zeile[i+1]);
    while Zahl>255 do Zahl:=Zahl-223;
    Zeile[i]:=Chr(Zahl);
  end;
  Result:=Zeile;
end;

function DecodeString(TextString, pwd: string):string;
var
  Zeile,pwdZeile:string;
  i,Anzahl,Zahl,pwdZahl:Integer;
begin
  Result:='';
  if TextString='' then Exit;
  pwdZahl:=GetCheckSum(pwd);
  pwdZeile:='';
  Result:='';
  Anzahl:=Length(TextString);
  while Length(pwdZeile)<Anzahl do pwdZeile:=pwdZeile+pwd;
  Dec(Anzahl);
  Zeile:='';
  for i:=1 to Anzahl do begin
    Zahl:=Ord(TextString[i])-Ord(pwdZeile[i])-Ord(TextString[i+1]);
    while Zahl<32 do Zahl:=Zahl+223;
    Zeile:=Zeile+Chr(Zahl);
  end;
  Zeile:=LeftStr(Zeile,Anzahl);
  for i:=1 to Anzahl do begin
    Zahl:=Ord(Zeile[i])-Ord(pwdZeile[i])-pwdZahl;
    while Zahl<32 do Zahl:=Zahl+223;
    Zeile[i]:=Chr(Zahl);
  end;
  Result:=Zeile;
end;

function GetCheckSum(TextString: string): LongInt;
var
  i:Integer;
begin
  Result:=0;
  for i:=1 to Length(TextString) do Result:=Result+Ord(TextString[i])
end;


Mein Ziel war es Strings zu erzeugen, die trotz gleichem (verschlüsseltem) Inhalt nicht gleich aussehen. Dazu hänge ich einen Zufallsbuchstaben an. Da der String einmal vorwärts und danach noch einmal rückwärts kodiert wird, erreiche ich eben diesen Effekt.

Schöne Grüße aus dem Norden
blaskito
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 17.07.09 11:40 
Mehr oder weniger eine monoalphabethische Verschlüsslung und daher anfällig für Kreuzkorrellationen. Ferner kann man sich, da der Zufallswert mit im Klartext auftaucht, ganz einfach die Daten (Seed) als auch das PW wiederherstellen. Einem ernsthaften Angreifer hält das sicherlich nicht lange stand ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 762
Erhaltene Danke: 127



BeitragVerfasst: Fr 17.07.09 12:23 
Der erste Teil der Chiffre ist eine polyalphabetische Substitution ähnlich Vigenère und wäre mit dem Kasiski-Test bei längeren Texten (ca. ab 100 Zeichen, je nach PW-Länge) zu knacken. Durch die zusätzliche Rückwärtsverschlüsselung mit Summe des jeweils rechten Buchstabens hast Du so eine Art Autokey-Vigenère-Chiffre entwickelt, die für Otto Normalverbraucher kaum zu knacken ist.
Das Problem ist allerdings das Passwort. Da es ja auch irgendwo gespeichert sein muss (für Ini-Dateien), kann man es relativ leicht auslesen und die Sicherheit leidet erheblich.

ub60
blaskito Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Win2003, 2008, 2012, WinXP, Win7
Delphi 6 Pers.
BeitragVerfasst: Fr 17.07.09 20:20 
Hallo und Danke für das Feedback,

die Sache mit dem letzten zufälligen Buchstaben bekomme ich hin aber dumm natürlich, dass das Passwort zur Verschlüsselung im Programm irgendwo steht. Das kann ich dann ja auch leicht auslesen :oops: . Ich vergrab mich nochmal hinterm Notebook und knobel noch ein wenig ...

Gruß aus dem Norden
blaskito