unit UJiaMi;
interface
uses Windows, Messages, SysUtils, Classes;
const
C1 = 52845;
C2 = 22719;
type
TJiaMi= class(TComPonent)
private
protected
public
constructor Create(AOwner: TComponent);
destructor Destroy
override;
function JiaMiS(const S: String
Key: Word): String;
function JieMiS(const S: String
Key: Word): String;
procedure JiaMiFile(INFName, OutFName : String
Key : Word);
procedure JieMiFile(INFName, OutFName : String
Key : Word);
published
end;
procedure Register;
implementation
{$R *.res}
procedure Register;
begin
RegisterComponents('LiQi', [TJiaMi]);
end;
{ TJiaMi }
constructor TJiaMi.Create(AOwner: TComponent);
begin
inherited;
end;
destructor TJiaMi.Destroy;
begin
inherited;
end;
procedure TJiaMi.JiaMiFile(INFName, OutFName: String
Key: Word);
VAR
MS, SS : TMemoryStream;
X : Integer;
C : Byte;
begin
MS := TMemoryStream.Create;
SS := TMemoryStream.Create;
TRY
MS.LoadFromFile(INFName);
MS.Position := 0;
FOR X := 0 TO MS.Size - 1 DO
begin
MS.Read(C, 1);
C := (C xor (Key shr 8));
Key := (C + Key) * C1 + C2;
SS.Write(C,1);
end;
SS.SaveToFile(OutFName);
FINALLY
SS.Free;
MS.Free;
end;
end;
function TJiaMi.JiaMiS(const S: String
Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
end;
end;
procedure TJiaMi.JieMiFile(INFName, OutFName: String
Key: Word);
VAR
MS, SS : TMemoryStream;
X : Integer;
C, O : Byte;
begin
MS := TMemoryStream.Create;
SS := TMemoryStream.Create;
TRY
MS.LoadFromFile(INFName);
MS.Position := 0;
FOR X := 0 TO MS.Size - 1 DO
begin
MS.Read(C, 1);
O := C;
C := (C xor (Key shr 8));
Key := (O + Key) * C1 + C2;
SS.Write(C,1);
end;
SS.SaveToFile(OutFName);
FINALLY
SS.Free;
MS.Free;
end;
end;
function TJiaMi.JieMiS(const S: String
Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(S[I]) + Key) * C1 + C2;
end;
end;
end.[:)]