下面的Demo可以满足你的要求吗?<br><br>unit EncryptIt;<br><br>interface<br>uses<br> Classes;<br>const<br> C1 = 52845;<br> C2 = 22719;<br><br>function Encrypt(const S: String; Key: Word): String;<br>function Decrypt(const S: String; Key: Word): String;<br>procedure EncryptFile(INFName, OutFName : String; Key : Word);<br>procedure DecryptFile(INFName, OutFName : String; Key : Word);<br><br>implementation<br><br>function Encrypt(const S: String; Key: Word): String;<br>var<br> I: Integer;<br>begin<br> Result := S;<br> for I := 1 to Length(S) do<br> begin<br> Result := char(byte(S) xor (Key shr 8));<br> Key := (byte(Result) + Key) * C1 + C2;<br> end;<br> end;<br><br>function Decrypt(const S: String; Key: Word): String;<br>var<br> I: Integer;<br>begin<br> Result := S;<br> for I := 1 to Length(S) do<br> begin<br> Result := char(byte(S) xor (Key shr 8));<br> Key := (byte(S) + Key) * C1 + C2;<br> end;<br>end;<br><br><br>procedure EncryptFile(INFName, OutFName : String; Key : Word);<br>var<br> MS, SS : TMemoryStream;<br> X : Integer;<br> C : Byte;<br>begin<br> MS := TMemoryStream.Create;<br> SS := TMemoryStream.Create;<br> try<br> MS.LoadFromFile(INFName);<br> MS.Position := 0;<br> for X := 0 TO MS.Size - 1 do<br> begin<br> MS.Read(C, 1);<br> C := (C xor (Key shr 8));<br> Key := (C + Key) * C1 + C2;<br> SS.Write(C,1);<br> end;<br> SS.SaveToFile(OutFName);<br> finally<br> SS.Free;<br> MS.Free;<br> end;<br>end;<br><br>procedure DecryptFile(INFName, OutFName : String; Key : Word);<br>var<br> MS, SS : TMemoryStream;<br> X : Integer;<br> C, O : Byte;<br>begin<br> MS := TMemoryStream.Create;<br> SS := TMemoryStream.Create;<br> try<br> MS.LoadFromFile(INFName);<br> MS.Position := 0;<br> for X := 0 to MS.Size - 1 do<br> begin<br> MS.Read(C, 1);<br> O := C;<br> C := (C xor (Key shr 8));<br> Key := (O + Key) * C1 + C2;<br> SS.Write(C,1);<br> end;<br> SS.SaveToFile(OutFName);<br> finally<br> SS.Free;<br> MS.Free;<br> end;<br>end;<br><br>end.<br>