delphi简单加密解密


本文整理自网络,侵删。

 delphi简单加密解密

uses WinCRT;
const
C1 = 52845;
C2 = 22719;
function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result[0] := S[0];
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: byte;
begin
Result[0] := S[0];
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;

var
S: string;
begin
Write('>');
ReadLn(S);
S := Encrypt(S,12345);
WriteLn(S);
S := Decrypt(S,12345);
WriteLn(S);
end.
//////////////////////////////////////////////////////
unit Unit2;

interface

Const Allchar: string = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789';

procedure Encrypt( var ss: string );

implementation

procedure Encrypt( var ss: string );
var l, lac, // string length
sp, // ss char pointer
cp: integer; // allchar pointer
begin
l := Length(ss);
lac := Length( Allchar );
sp := 1;
while sp <= l do begin
cp := 1;
while (allchar[cp] <> ss[sp]) and ( cp <= lac ) do inc( cp );
if cp > lac then ss[sp]:= '*'
else begin
ss[sp] := allchar[ lac - cp + 1 ]; //first char result in the last
end;
inc(sp);
end;
end;


end.

相关阅读 >>

Delphi调用外部程序并等待其运行结束

Delphi adoquery判断插入的值是否重复

Delphi开发桌面图标列表查看程序

Delphi中获取guid的函数

Delphi winapi: inflaterect - 改变矩形大小

Delphi 数字摇号器

Delphi memo1文本搜索并高亮

Delphi dbnavigator1 删除时弹出确认对话框

Delphi thttprio 控件调用webservice超时问题

Delphi 如何将access的ole对象字段存储的bmp图象显示出来

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



打赏

取消

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

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

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

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

评论

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