EncryptIt.pas


本文整理自网络,侵删。

 
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[I] := char(byte(S[I]) xor (Key shr 8));            Key := (byte(Result[I]) + 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[I] := char(byte(S[I]) xor (Key shr 8));            Key := (byte(S[I]) + 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. 

相关阅读 >>

Delphi研究之驱动开发篇(六)--利用section与用户模式程序通讯(上)

Delphi winapi: extracticon - 获取 exe、dll 或 ico 文件中的图标

Delphi 调试ios时出现 please specify exact device preset uuid

Delphi加载驱动的代码演示

Delphi xe开发 android 开机自动启动

Delphi 使控件支持鼠标滚轴消息

winapi 字符及字符串函数(7): ischarlower - 是否是个小写字母

最简单的Delphi程序(控制台)

Delphi opendialog文件过滤类型

Delphi 的链式代码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...