AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

RC4 und Delphi.Net

Ein Thema von skyware · begonnen am 16. Okt 2004 · letzter Beitrag vom 17. Okt 2004
Antwort Antwort
skyware

Registriert seit: 11. Dez 2002
Ort: Wetzikon, Zürich
151 Beiträge
 
Delphi 6 Enterprise
 
#1

Re: RC4 und Delphi.Net

  Alt 17. Okt 2004, 15:07
Hallo zusammen,

danke für Eure Unterstützung, leider hab ich immer noch 2 Problemchen
die ich seit gestern nicht lösen konnte, bin am verzweifeln
Die Codezeilen die mir noch Probleme bereichen sind mit "//todo" markiert.
Hab scho diverses versucht mit Byte casten, mit Convert.GetBase64FromString etc.,
hat alles nichts geholfen
Please help

ps: Lars, unsafe Code möcht ich eigentlich vermeiden

Delphi-Quellcode:
unit HTFunctions_Crypt_RC4;

interface

uses
  {$IFDEF CLR}Borland.Vcl.SysUtils{$ELSE}SysUtils{$ENDIF};


function RC4Encode(const AString, AKey: string): string;
function RC4Decode(const AString, AKey: string): string;


implementation

type
  TRC4Context = record
    FD : array[Byte] of Byte;
    FI,
    FJ : Byte;
  end;

{ RC4Init:
-------------------------------------------------------------------------------}

procedure RC4Init(var ARC4: TRC4Context; const AKey: String);
var
  xR,
  xS,
  xT,
  xK : Byte;
  xU,
  xL : Integer;
begin
  xL := Length(AKey);
  with ARC4 do
  begin
    FI := 0;
    FJ := 0;
    for xS := 0 to 255 do FD[xS] := xS;
    xR := 0;
    xU := 0;
    for xS := 0 to 255 do
    begin
      {$IFDEF CLR}
      if xU < xL then xK := Byte(AKey[xU+1]) else xK := 0;
      {$ELSE}
      if xU < xL then xK := PByteArray(AKey)[xU] else xK := 0;
      {$ENDIF}
      Inc(xU);
      if xU >= xL then xU := 0;

      Inc(xR, FD[xS] + xK);
      xT := FD[xS];
      FD[xS] := FD[xR];
      FD[xR] := xT;
    end;
  end;
end;

{ RC4Code:
-------------------------------------------------------------------------------}

procedure RC4Code(var ARC4: TRC4Context; const ASource; var Dest; ACount: Integer);
var
  xS : Integer;
  xT : Byte;
begin
  with ARC4 do
    for xS := 0 to ACount -1 do
    begin
      Inc(FI);
      xT := FD[FI];
      Inc(FJ, xT);
      FD[FI] := FD[FJ];
      FD[FJ] := xT;
      Inc(xT, FD[FI]);
      {$IFDEF CLR}
      //todo
      TByteArray(Dest)[xS] := TByteArray(ASource)[xS] xor FD[xT];
      {$ELSE}
      TByteArray(Dest)[xS] := TByteArray(ASource)[xS] xor FD[xT];
      {$ENDIF}
    end;
end;

{ RC4Done:
-------------------------------------------------------------------------------}

procedure RC4Done(var ARC4: TRC4Context);
begin
  //todo
  FillChar(ARC4, SizeOf(ARC4), 0);
end;

{ RC4Encode:
-------------------------------------------------------------------------------}

function RC4Encode(const AString, AKey: string): string;
var
  xRC4 : TRC4Context;
begin
  SetLength(Result, Length(AString));
  RC4Init(xRC4, AKey);
  RC4Code(xRC4, AString[1], Result[1], Length(AString));
  Rc4Done(xRC4);
end;

{ RC4Decode:
-------------------------------------------------------------------------------}

function RC4Decode(const AString, AKey: string): string;
var
  xRC4 : TRC4Context;
begin
  SetLength(Result, Length(AString));

  RC4Init(xRC4, AKey);
  RC4Code(xRC4, AString[1], Result[1], Length(AString));
  Rc4Done(xRC4);
end;


end.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz