delphi 简单的英文数字字符串加密解密函数(不支持中文)


本文整理自网络,侵删。

 
function EncryptSettings(Str : String): String;
var
X, Y : Integer;
A : Byte;
Key:string;
begin
Key:='Fi7ke'; //这个是加密钥匙,你可以随便设置,但解密钥匙要一样,不然解不了密
Y := 1;
for X := 1 to Length(Str) do
begin
A := (ord(Str[X]) and $0f) xor (ord(Key[Y]) and $0f);
Str[X] := char((ord(Str[X]) and $f0) + A);
Inc(Y);
If Y > length(Key) then Y := 1;
end;
Result := Str;
end;


function DecryptSettings(Str : String): String;
var
X, Y : Integer;
A : Byte;
Key:string;
begin
Key:='Fi7ke'; //注意了,这里要和加密钥匙一样.
Y := 1;
for X := 1 to Length(Str) do
begin
A := (ord(Str[X]) and $0f) xor (ord(Key[Y]) and $0f);
Str[X] := char((ord(Str[X]) and $f0) + A);
Inc(Y);
If Y > length(Key) then Y := 1;
end;
Result := Str;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
memo2.Text:=EncryptSettings(memo1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.Text:=DecryptSettings(memo2.Text);
end;

相关阅读 >>

Delphi 图像处理 二值化

Delphi ascii 码对照表

Delphi formatdatetime 显示日期时间

Delphi资源文件的详细使用方法

Delphi 注册表管理

Delphi 图像操作

Delphi 在ms access数据库中图像的存储和显示

Delphi数据库实现从最后一条记录向上查询至首记录

Delphi 本地数据库备份与还原(Delphi)

Delphi tdictionary 泛型如何排序

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



打赏

取消

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

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

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

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

评论

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