delphi 简单的字符串加密和解密


本文整理自网络,侵删。

 


unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    Edit3: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//首先定义一个常量数组
const
      XorKey:array[0..7] of Byte=($A1,$B7,$AC,$57,$1C,$63,$3B,$81); //字符串加密用

      //在程序里加入以下两个函数,

function Enc(Str:String):String;//字符加密函?? ?@是用的一????或加密
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
   begin
     Result:=Result+IntToHex(Byte(Str[i]) xor XorKey[j],2);
     j:=(j+1) mod 8;
   end;
end;
function Dec(Str:String):String;//字符解密函??
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) div 2 do
   begin
     Result:=Result+Char(StrToInt('$'+Copy(Str,i*2-1,2)) xor XorKey[j]);
     j:=(j+1) mod 8;
   end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
if edit1.Text<>'' then
begin
  Edit2.Text:= Enc(Edit1.text);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Edit3.Text:= Dec(Edit2.text);
end;

end.

https://blog.csdn.net/qq_33536143/article/details/85721391

相关阅读 >>

idhttp访问网页出现socket error #10054错误

Delphi下firedac连接mysql数据库零起点

Delphi andorid应用程序检查wifi有效还是无效

Delphi获得webbrowser中的html文本

Delphi简单判断程序30秒没有键盘和鼠标动作示例

Delphi写进程管理器

Delphi之如何快速开发原生activex控件

Delphi xe5在zip文件中添加某个txt文件并写入文字

Delphi 检查屏幕是否处于锁屏或关闭状态

Delphi 压缩图片算法

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



打赏

取消

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

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

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

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

评论

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