那位大侠有RC4的算法原代码?
急用!QQ:52943597 EMAIL:[email protected]
急用!QQ:52943597 EMAIL:[email protected]
解决方案 »
- 寻求兼职开发人员
- 双击*.dpr和通过FILE-OPEN有何不同
- 请教DBGRIDEH的用法 请大家看一下(着急在线等待)分不够再加
- 救命啊!!!怎么读取本机的主板号??请各位大侠救救我!!
- 怎样使用自己定制的光标呢,我试过不行,请问如何解决
- TdbChart怎么画数据库的图啊,问什么总是之画一个数据呢?在线等待,立刻给分!
- 我的ADO数据库程序不能在别的电脑上运行,请问怎么做。急!!!!!!!!!!!!!
- ODBC连接SYBASE数据库问题。急,在线等待!
- 有谁知道制作演示用的软件——象Lotus 1-2-3中的
- 有无朋友喜欢linux+delphi+oracle
- 哪位有关于施工企业管理的需求文档,请给我发一份。
- 问个弱弱的问题
{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.