Thema: Delphi RC4 Problem

Einzelnen Beitrag anzeigen

fortuneNext

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

Re: RC4 Problem

  Alt 30. Okt 2008, 22:22
Nah, zur einfachheit poste ich einfach mal meinen gesamten Text.

Also ich wollte das gerne - nur zum erstmaligen Verständnis - in eine einzige Funktion umschreiben.
Achtung - die Variablen heißen ein wenig anders, da ich das Ding komplett neu abgeschrieben hab, ums besser zu verstehen.

Delphi-Quellcode:
function TfMain.Encrypt_RC4(uncrypted,password:string):string;
type
  TRC4Context = record
    D: array[byte] of Byte;
    I,J: byte;
  end;
var
  R,S,T,K:byte;
  U,L,N,Count:integer;
  X:TRC4Context;
begin
  Count := length(uncrypted);
  L := Length(password);
  with x do
  begin
    I := 0;
    J := 0;
    for S := 0 to 255 do
      D[S] := S;
    R := 0;
    U := 0;
    for S := 0 to 255 do
    begin
      if U < L then K := PByteArray(password)[U] else K := 0;
      Inc(U);
      if U >= L then U := 0;
      Inc(R, D[S] + K);
      T := D[S];
      D[S] := D[R];
      D[R] := T;
    end;
    for N := 0 to Count -1 do
    begin
      Inc(I);
      T := D[I];
      Inc(J, T);
      D[I] := D[J];
      D[J] := T;
      Inc(T, D[I]);
      TByteArray(Result)[N] := TByteArray(uncrypted)[N] xor D[T];
    end;
  end;
  FillChar(x, SizeOf(x), 0);
end;

Das ist jetzt die ganze Funktion.
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