哈哈,这是一个DFW以前出现过的函数!简单一点但也还可以用!
-------------------------------------------------------
function EncrypKey(Src: String; Key: String): String;
//加密函数 Src为输入string;key:密匙; 返回一个加密后string
var
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc :Integer;
Range :Integer;
begin
KeyLen:=Length(Key);
if KeyLen = 0 then
key:='winsong2006';
KeyPos:=0;
Range:=256;
Randomize;
offset:=Random(Range);
dest:=format('%1.2x',[offset]);
for SrcPos := 1 to Length(Src) do
begin
SrcAsc:=(Ord(Src[SrcPos]) + offset) MOD 255;
if KeyPos < KeyLen then
KeyPos:= KeyPos + 1
else
KeyPos:=1;
SrcAsc:= SrcAsc xor Ord(Key[KeyPos]);
dest:=dest + format('%1.2x',[SrcAsc]);
offset:=SrcAsc;
end;
Result:=Dest;
end;
function UnEncrypKey(Src: String; Key: String): String;
//解密函数 Src:加密后string; key:密匙,一定要与加密的key相同;
//返回 加密前string
var
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc:Integer;
TmpSrcAsc :Integer;
begin
KeyLen:=Length(Key);
if KeyLen = 0 then
key:='winsong2006';
KeyPos:=0;
offset:=StrToInt('$'+ copy(src,1,2));
SrcPos:=3;
repeat
try
SrcAsc:=StrToInt('$'+ copy(src,SrcPos,2));
except
end;
if KeyPos < KeyLen Then
KeyPos := KeyPos + 1
else
KeyPos := 1;
TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);
if TmpSrcAsc <= offset then
TmpSrcAsc := 255 + TmpSrcAsc - offset
else
TmpSrcAsc := TmpSrcAsc - offset;
dest := dest + chr(TmpSrcAsc);
offset:=srcAsc;
SrcPos:=SrcPos + 2;
until SrcPos >= Length(Src);
Result:=Dest;
end;
----------------------------------------------------------------
一般要求不高string加密的可以用它
[
]