delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
我有个简单网络传输加密的想法,但不会实现,请高手给出代码 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiNetwork/html/delphi_20061203182915209.html
把数据加密后再通过套接字函数发送出去       接收方收到后再解密  
   
   
  所谓加密就是   对数据隔位取反   再把数据调整位置(第一位和第二位对调,第三和第四   等等)。  
   
  但是我刚学delphi     不是怎么把字符串数据转为二进制     请高手给出加密解密代码

请高手现身  
   
  请高手献身

怎么没人??

你出的题难呗,会ASM的都不在。  
   
  字符串好说:  
   
  var  
  s:string;  
  buf:pchar;  
  buf1:array   of   byte;  
  begin  
    s:='hihisdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdf';  
    getmem(buf,length(s));  
    setlength(buf1,length(s));  
    hextobin(pchar(s),buf,length(s));  
    copymemory(@buf1[0],buf,length(s));  
    showmessage(inttostr(buf1[0]));  
    freemem(buf);  
  end;  
   
  取反  
  var  
  a,b:byte;  
  begin  
  a:=$f0;  
  b:=not   a;  
  showmessage(inttostr(b));  
   
  隔位取反和移位的要求比较难以实现,等高手来吧。  
 

多谢楼上的  
   
  我的网络加密     还有数字   特殊字符   汉字     都能处理吗?  
   
  或者不按我出的加密方法     你们有什么变化多端的加密方法??  
   
  给我加密解密函数     最好是每次加密结果都不一样的

procedure   Encode(var   buf;   size:   Integer);  
  var  
      T:   Byte;  
      P1,   P2:   PByte;  
  begin  
      P1   :=   PByte(@Buf);  
      P2   :=   PByte(PChar(@Buf)   +   1);  
      while   Size   >   0   do  
      begin  
          T   :=   P2^;  
          P2^   :=   not   P1^;  
          P1^   :=   not   T;  
          Inc(P1,   2);  
          Inc(P2,   2);  
          Dec(Size,   2);  
      end;  
  end;  
   
  procedure   Decode(var   Buf;   Size:   Integer);  
  begin  
      Encode(Buf,   Size);  
  end;

同样的输入,得到同样的输出。  
   
  好似   不可能每次加密结果都不一样。

用随机密钥加密         在连同密钥和加密之后的密文传过来不就行了?  
   
  但是我不会实现

用加密算法加解密不就行了吗

楼上的     我是初学者  
   
  难道delphi自带了这种函数??     函数名是什么??   在哪个pas里定义的??       要求加密过程利用密钥的         而且可加密特殊字符和汉字

a是加密的数据,如果2,4,6,8取反   b是加密后的  
  b:=   a   or   ((not   a)and   85)  
 

上面的错了,这个  
   
  a是加密的数据,如果2,4,6,8取反   b是加密后的  
  b:=   (a   and   170)   or   ((not   a)and   85)  
  CHR也是字节值,所以有ORD()可以转换起ASCII值  
  //==================================================  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
  a,b:integer;  
  begin  
      a:=100;  
      b:=(a   and   170)   or   ((not   a)and   85)   ;  
      edit1.Text   :=inttostr(b);  
  end;

function   encode(a   :   byte):byte  
  var   b   :   byte;  
  begin  
      b   :=   a   xor   85;   //隔位取反  
      Result   :=   (b   shl   1)   and   170   or   (b   shr   1)   and   85;     //邻位对调  
  end;

posted on 2009-03-02 11:34 delphi2007 阅读(392) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。