那位大侠有RC4的算法原代码?
急用!QQ:52943597 EMAIL:[email protected]

解决方案 »

  1.   

    RC4是什么?加密算法?不懂,帮你up
      

  2.   

    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4653&lngWId=3不是 delphi 的
      

  3.   

    unit Rc4unit;interface
    {Declare the compiler defines}
    {$I CRYPTDEF.INC}
    {------Changeable compiler switches-----------------------------------}
    {$A+   Word align variables }
    {$F+   Force Far calls }
    {$K+   Use smart callbacks
    {$N+   Allow coprocessor instructions }
    {$P+   Open parameters enabled }
    {$S+   Stack checking }
    {$T-   @ operator is NOT typed }
    {$IFDEF DELPHI}
    {$U-   Non Pentium safe FDIV }
    {$Z-   No automatic word-sized enumerations}
    {$ENDIF}
    {---------------------------------------------------------------------}
    {.$DEFINE TEST}
    uses SysUtils, Cryptcon{$IFDEF DELPHI}, Classes, Controls{$ENDIF}
         {$IFDEF BP7},objects{$ENDIF};type
    {$IFDEF DELPHI}
     TRC4 = class(TCrypto)
    {$ENDIF}
    {$IFDEF BP7}
     PRC4 = ^TRC4;   {For BP7 Objects}
     TRC4 = object(TCrypto)
    {$ENDIF}
     Private
      {RC4 Key Elements}
      FState: Array[0..255] of BYTE;
      FI: BYTE;
      FJ: BYTE;
     {$IFDEF DELPHI}
      Procedure SetKeys;       override; {Sets up En\DecipherKey SubKeys}
      Procedure Encipher_Bytes;override;
      Procedure Decipher_Bytes;override;
    {$ENDIF}
    {$IFDEF BP7}
      Procedure Encipher_Bytes; virtual;
      Procedure Decipher_Bytes; virtual;
      Procedure SetKeys;        virtual; {Sets up En\DecipherKey SubKeys}
    {$ENDIF}
     public
        { Public declarations }
    {$IFDEF DELPHI}
      constructor Create(Owner: TComponent);override;
    {$ENDIF}
    {$IFDEF BP7}
      constructor Init;
    {$ENDIF}
    end;{TRC4}{$IFDEF DELPHI}
     procedure Register;{register the component to the Delphi toolbar}
    {$ENDIF}implementation{$IFDEF DELPHI}
    procedure Register;
      {Registers the Component to the toobar, on the tab named 'Crypto'}
      {Now all a Delphi programmer needs to do is drag n drop to have
       Blowfish encryption}
    begin
      RegisterComponents('Crypto', [TRC4]);
    end;
    {$ENDIF}{==================================TRC4========================================}{$IFDEF DELPHI}
    constructor TRC4.Create(Owner: TComponent);
    {$ENDIF}
    {$IFDEF BP7}
    constructor TRC4.Init;
    {$ENDIF}
    begin
    { Decipher_Bytes := @Encipher_Bytes;}
    {$IFDEF DELPHI}
      inherited Create(Owner);
    {$ENDIF}
    end;Procedure TRC4.SetKeys;
    {------------------------------------------------------------------------------
     Initializing the S-Box.  First fill it linearly: So=0, S1=1...S255=255.
     Then fill another 256byte array with the key, repeating the key as necessary
     to fill the entire array: K0, K1..K255.
     Then
     j=0
     for i=0 to 255
      j = (j + Si + Ki) mod 256
      swap Si and Sj
    -------------------------------------------------------------------------------}
    var
     KeyLen, j: WORD; i, swapbyte: BYTE;
     K: Array[0..255] of BYTE;begin
     KeyLen := Length(FKey);
     FI := 0; FJ := 0;j := 0;
     for i:= 0 to 255 do begin
      FState[i] := i; K[i] := BYTE(FKey[(i MOD KeyLen) + 1]);
     end;
     for i := 0 to 255 do begin
      j := (j + FState[i] + K[i]) MOD 256;
      swapbyte := FState[i]; FState[i] := FState[j]; FState[j] := swapbyte;
     end;
    end;{SetKeys}Procedure TRC4.Encipher_Bytes;
    {------------------------------------------------------------------------------
     i=j=0 i=(i + 1) mod 256
     j=(j + Si) mod 256
     swap Si and Sj
     t = (Si + Sj) mod 256
     K = St the BYTE K is XOR withe plaintext to produce ciphertext or XORED with
     the ciphertext to produce plaintext We assume that the data to encipher is in FBuffer, and FInputLength holds the
     length of FBuffer.
     ------------------------------------------------------------------------------}
     var
      i, j, t, swapbyte: BYTE;
      x: WORD;
     begin
      i:= FI; j:= FJ;  For x := 0 to (FInputLength - 1) do begin
       i := (i + 1) MOD 256;
       j := (j + FState[i]) MOD 256;
       swapbyte := FState[i]; FState[i] := FState[j]; FState[j] := swapbyte;
       t := (FState[i] + FState[j]) MOD 256;
       FOutputArray^[x] := FState[t] Xor FBuffer[x];
      end;  FI := i;
      FJ := j;
     end;Procedure TRC4.Decipher_Bytes;
    begin
     Encipher_Bytes;
    end;
    end.
      

  4.   

    不好意思,还有很长,留下你的email,我发给你
      

  5.   

    能不能也将RC4的代码发给我,[email protected],谢谢了。