只有30分了!求文件加密算法!(30分)

  • 主题发起人 主题发起人 sima
  • 开始时间 开始时间
S

sima

Unregistered / Unconfirmed
GUEST, unregistred user!
smhp@163.net
 
AES,DES网上都有,自己也可写个简单点的:)
 
unit EncryptIt;

interface
USES
Classes;
const
C1 = 52845;
C2 = 22719;

function Encrypt(const S: String; Key: Word): String;
function Decrypt(const S: String; Key: Word): String;
procedure EncryptFile(INFName, OutFName : String; Key : Word);
procedure DecryptFile(INFName, OutFName : String; Key : Word);

implementation

function Encrypt(const S: String; Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(Result) + Key) * C1 + C2;
end;
end;

function Decrypt(const S: String; Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(S) + Key) * C1 + C2;
end;
end;


procedure EncryptFile(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;

procedure DecryptFile(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;

end.
 
试一试 TurboPower 的 LockBox 2 吧。
http://bkfx.51.net/download/lockbox206.rar
 
这个加密算法未必也太简单了吧?
 
呵呵,是啊!其实算法我这里已经解决了,只是想看看大家的解决方案!
 
接受答案了.
 
后退
顶部