DELPHI 写的经常用到的加解密函数


本文整理自网络,侵删。

 以下程序可直接用,拷贝就可以了,希望可以起到抛砖引玉的作用。
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

相关阅读 >>

Delphi 实现拦截api的钩子(hook)

Delphi adoquery的post和updatebatch

Delphi简单的播放声音

Delphi的idhttp报508 loop detected错误的原因

Delphi goto 语句的使用

Delphi 破解access密码

Delphi 网上获取北京时间验证码识别之中值滤波

Delphi tstreamwriter快速写入文件

Delphi中简单的调用单元unit实例

Delphi研究之驱动开发篇(五)--使用后备列表

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



打赏

取消

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

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

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

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

评论

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