我想把一个字符串加密
让别人不能显示的看到他是什么,但要能够恢复出来
让别人不能显示的看到他是什么,但要能够恢复出来
解决方案 »
- 如何用directshow实时采集图像压缩为mpeg-4文件?
- 关于QRDBText的问题!急!急!急
- 大家做过在线升级的功能吗?
- CommaText是何意思?最好给一个例子
- 请zjcxc(: 邹建 :)
- 使用TDBGridEh出生的问题
- delphi如何调用c#的dll?
- 关于“欢迎聚焦‘软件沙龙’”中,出现问题的指正
- fastReport怎么让图片的FileLink指向一个变量呢
- 关于Dll引出MDIChild的问题各位看看!hellion(恶人)和liang_z(千山一刀之忍者神龟)
- 一个使用NMUDP控件后产生的错误,不知道是不是控件有问题,请明白人指点一下,谢谢!
- Delphi6中文版
SeedB = 32; /// 字符加密常量function TSYSMAIN.Crypt(const s: String; Key: Word; const bEncrypt: boolean = True): String;
var //字符串加解密
i : integer;
ps, pr : ^byte;
begin
SetLength(Result, Length(s));
ps := @s[1];
pr := @Result[1];
for i := 1 to length(s) do
begin
pr^ := ps^ xor (Key shr 8);
if bEncrypt then
Key := (pr^ + Key) * SeedA + SeedB
else
Key := (ps^ + Key) * SeedA + SeedB;
pr := pointer(integer(pr) + 1);
ps := pointer(integer(ps) + 1);
end
end;
//加密字符串数据
var
the_length:Integer;
begin
For the_length:=1 to length(sourec_str) do
begin
if (ord(sourec_str[the_length])>=58) and (ord(sourec_str[the_length])<=122) then
result:=result+chr(ord(sourec_str[the_length])-10)
else
if (ord(sourec_str[the_length])>=48) and (ord(sourec_str[the_length])<=57) then
result:=result+chr(ord(sourec_str[the_length])-20)
else
result:=result+sourec_str[the_length];
end;
end;Function unencrypt_str(sourec_str:String):String;
//解密字符串
var
the_length:Integer;
begin
For the_length:=1 to length(sourec_str) do
begin
if (ord(sourec_str[the_length])>=28) and (ord(sourec_str[the_length])<=37) then
result:=result+chr(ord(sourec_str[the_length])+20)
else
if (ord(sourec_str[the_length])>=48) and (ord(sourec_str[the_length])<=112) then
result:=result+chr(ord(sourec_str[the_length])+10)
else
result:=result+sourec_str[the_length];
end;
end;
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;