觀點中國 CnEyes...
只有想不到的.没有做不到的! For Evreth ing Making For Anything 才子世界 Esprit World!
posts - 80,comments - 83,trackbacks - 0
<2025年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

有了您的关注.生活才会更精彩.专业,成就事业!

常用链接

留言簿(5)

随笔档案(80)

文章分类(33)

文章档案(33)

相册

My Links

最新随笔

搜索

  •  

积分与排名

  • 积分 - 40137
  • 排名 - 143

最新评论

阅读排行榜

评论排行榜

一個加密算法

 

interface

USES

    Classes;

const

     C1 = 52845;

     C2 = 22719;

 

function Encrypt( S: String; Key: Word): String;

function Decrypt( S: String; Key: Word): String;

 

implementation

function Encrypt( S: String; Key: Word): String;

var

   I: Integer;

   j: 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;

 s:=Result;

 Result:='';

 for i:=1 to length(s) do

 begin

  j:=Integer(s[i]);

  Result:=Result + Char(65+(j div 26))+Char(65+(j mod 26));

 end;

end ;

 

function Decrypt( S: String; Key: Word): String;

var

   I: Integer;

   j: Integer;

begin

 result:='';

 for i:=1 to (length(s) div 2) do

 begin

  j:=(Integer(s[2*i-1])-65)*26;

  j:=j+(Integer(s[2*i])-65);

  result:=result + Char(j);

 end;

 s:=result;

 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 ;

 

end .

 

運行結果: 圖片1.png

posted on 2006-07-28 12:43 才子£鸣 阅读(469) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。