以下程序可直接用,拷贝就可以了,希望可以起到抛砖引玉的作用。
function StrDecrypt(s: string; key: word): string;
var
i:byte;
const
fc1=2;
fc2=3;
begin
//result[0]:=s[0];
setlength(result,length(s),',',');
for i:=1 to length(s) do
begin
result[i]:=char(byte(s[i])xor (key shr 8),',',');
key:=(byte(result[i])+key)*fc1+fc2;
end;
end;
function StrEncrypt(s: string; key: word): string;
var
i:byte;
const
fc1=2;
fc2=3;
begin
setlength(result,length(s),',',');
for i:=1 to length(s) do begin
result[i]:=char(byte(s[i])xor(key shr 8),',',');
key:=(byte(s[i])+key)*fc1+fc2;
end;
end;
function CheckPassWord(Pass:string):String;
Var
Itm : Array [0..12] of integer;
i,j,k: Integer;
ppp : String;
Const
bb = ’ABCDEFGHIJKL‘;
begin
Pass:=LowerCase(Trim(Pass),',',');
k:=Length(Pass,',',');
j:=1;
ppp:='';
Itm[0]:=0;
if k<12 Then Pass:=Pass+Copy(bb,1,12-k,',',');
For i:=1 To 12 Do Begin
j:=j*2;
Itm[i]:=ord(Pass[i])+k+j;
Itm[0]:=Itm[0]+Itm[i];
End;
Itm[0]:=Itm[0] MOD 12;
For i:=1 To 12 Do
ppp:=ppp+inttostr(Itm[i],',',');
j:=Itm[0]+1;
k:=length(ppp,',',');
if k mod 2 =0 then k:=k-1;
For i:=1 to 12 Do Begin
if j>k then j:=j-k;
Result:=Result+ppp[j];
j:=j+2;
End;
end;
来源 http://blog.csdn.net/trassion/article/details/7283100
关键字词: