Einzelnen Beitrag anzeigen

fortuneNext

Registriert seit: 11. Aug 2007
Ort: Neuss
133 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: RC4 Problem bei Wikipedia-Pseudoquellcode

  Alt 12. Feb 2009, 15:47
Hey, ich habe nochmal eine Frage. Ich habe den Code jetzt vollständig umgesetzt:
Delphi-Quellcode:
procedure TRC4.Initialize(key: string);
var
  i: integer;
  j, swap: byte;
begin
  i := 0;
  j := 0;
  for i := 0 to length(Alg_RC4.sandbox) do
    sandbox[i] := i;
  for i := 0 to length(Alg_RC4.sandbox) do
  begin
    j := (j + Alg_RC4.sandbox[i] + ord(key[i mod length(key)])) mod length(Alg_RC4.sandbox);
    swap := Alg_RC4.sandbox[i];
    Alg_RC4.sandbox[i] := Alg_RC4.sandbox[j];
    Alg_RC4.sandbox[j] := swap;
  end;
end;

function TRC4.Crypt(text: string):string;
var
  i, x:integer;
  j, swap:byte;
begin
  i := 0;
  j := 0;
  Result := '';
  for x := 1 to length(text) do
  begin
    i := (i + 1) mod length(Alg_RC4.sandbox);
    j := (j + Alg_RC4.sandbox[i]) mod length(Alg_RC4.sandbox);
    swap := Alg_RC4.sandbox[i];
    Alg_RC4.sandbox[i] := Alg_RC4.sandbox[j];
    Alg_RC4.sandbox[j] := swap;
    if not x = length(text) then
      Result := Result + char(Alg_RC4.sandbox[(Alg_RC4.sandbox[i] + Alg_RC4.sandbox[j]) mod length(Alg_RC4.sandbox)] xor ord(text[x + 1]))
    else
      Result := Result + char(Alg_RC4.sandbox[(Alg_RC4.sandbox[i] + Alg_RC4.sandbox[j]) mod length(Alg_RC4.sandbox)]);
  end;
end;
Wobei sandbox ein array[byte] of byte; ist.

Der Algorithmus verschlüsselt zwar den String - aber nicht nach RC4. Stattdessen kommt ein verschlüsselter Code heraus, welcher jedenfalls nicht wie mit einem anderen RC4-Tool verschlüsselt aussieht und beim nochmaligen Verschlüsseln einfach sich selber weider ausgibt. Hauptproblem ist also: Die Verschlüsselten verändern sich beim nochmaligen Verschlüsseln nicht mehr, was sehr seltsam ist. Entschlüsselugn ist auch nicht möglich, obwohl normalerweise ja das 2. Verschlüsseln den Text wieder entschlüsseln müsste.

Entdeckt jemand, wo mein Fehler bei der RC4- Umsetzung liegt?

Danke!
mfg
fortuneNext
Tim
"Hilfe & Support konnte nicht geöffnet werden. Bitte öffnen sie Hilfe & Support, um das Problem zu beheben."
"No Keyboard found. Press F1 to continue."
  Mit Zitat antworten Zitat