| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 945 人关注过本帖
标题:DELPHI 加密原代码,支持任意长度的密码,16字节密码加密7兆文件只需半秒
只看楼主 加入收藏
oliphant
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-12-2
收藏
 问题点数:0 回复次数:0 
DELPHI 加密原代码,支持任意长度的密码,16字节密码加密7兆文件只需半秒


function Exchange(desaddr : pointer ; souaddr : pointer ; len : word ; toright : bool) : bool;
var
  mypbyte1 : pbyte;
  mypbyte2 : pbyte;
  mybyte : byte;
  i : integer;
begin
  result := false;
  if (len < 1) then exit;
  if (dword(desaddr) = 0) then exit;
  if (dword(souaddr) = 0) then exit;
  if (dword(desaddr) = dword(souaddr)) then exit;
  if (toright = true) then begin
    i := 0;
  end else begin
    i := len - 1;
  end;
  while (i >= 0) and (i <= len - 1) do begin
    mypbyte1 := pbyte(dword(desaddr) + i);
    mypbyte2 := pbyte(dword(souaddr) + i);
    mybyte := mypbyte1^;
    mypbyte1^ := mypbyte2^;
    mypbyte2^ := mybyte;
    if (toright = true) then begin
      i := i + 1;
    end else begin
      i := i - 1;
    end;
  end;
end;

function CountBinI(myaddr : pointer ; len : word) : dword;
var
  mypbyte : pbyte;
  myi : dword;
  i : integer;
  j : integer;
begin
  result := 0;
  if (len < 1) then exit;
  if (dword(myaddr) = 0) then exit;
  i := 0;
  while (i >= 0) and (i <= len - 1) do begin
    mypbyte := pbyte(dword(myaddr) + i);
    myi := 1;
    j := 0;
    while (j >= 0) and (j <= 7) do begin
      if (myi and mypbyte^ > 0) then result := result + 1;
      myi := myi shl 1;
      j := j + 1;
    end;
    i := i + 1;
  end;
end;

function NotBinI( desaddr : pointer ; souaddr : pointer ; len : word ) : bool;
var
  mypbyte1 : pbyte;
  mypbyte2 : pbyte;
  mybyte : byte;
  myi : byte;
  i : integer;
  j : integer;
begin
  result := false;
  if (len < 1) then exit;
  if (dword(desaddr) = 0) then exit;
  if (dword(souaddr) = 0) then exit;
  i := 0;
  while (i >= 0) and (i <= len - 1) do begin
    mypbyte1 := pbyte(dword(desaddr) + i);
    mypbyte2 := pbyte(dword(souaddr) + i);
    mybyte := 0;
    myi := 1;
    j := 0;
    while (j >= 0) and (j <= 7) do begin
      if (myi and mypbyte2^ = 0) then begin
        mybyte := mybyte + (myi and mypbyte1^);
      end else begin
        mybyte := mybyte + myi - (myi and mypbyte1^);
      end;
      myi := myi shl 1;
      j := j + 1;
    end;
    mypbyte1^ := mybyte;
    i := i + 1;
  end;
  result := true;
end;

function RO( myaddr : pointer ; len : word ; rocount : word ; toright : bool ) : bool;
label bac1;
label bac2;
label poi1;
label poi2;
label poi3;
label poi4;
var
  myaddress : dword;
  myflag : dword;
begin
  result := false;
  if (len < 1) or (rocount < 1) then exit;
  myaddress := dword(myaddr);
  myflag := 0;
  if (toright = true) then myflag := 1;
  asm
    push eax
    push ebx
    push ecx
    push edx
    push esi
    push edi
    mov esi , myflag
    xor edx , edx
    mov dx , rocount
    mov edi , edx
bac1:
    mov ebx , myaddress
    test esi , esi
    jne poi1
    xor eax , eax
    mov ax , len
    add ebx , eax
    dec ebx
poi1:
    push ebx
    xor ecx , ecx
    mov cx , len
    xor dx , dx
bac2:
    xor ax , ax
    test esi , esi
    je poi2
    mov ah , [ebx]
    shr ax , 1
    or ah , dl
    mov dl , al
    mov [ebx] , ah
    inc ebx
    jmp poi3
poi2:
    mov al , [ebx]
    shl ax , 1
    or al , dl
    mov dl , ah
    mov [ebx] , al
    dec ebx
poi3:
    dec ecx
    cmp ecx , 1
    jge bac2
    pop ebx
    mov dh , [ebx]
    or dh , dl
    mov [ebx] , dh
    dec edi
    cmp edi , 1
    jge bac1
    pop edi
    pop esi
    pop edx
    pop ecx
    pop ebx
    pop eax
  end;
  result := true;
end;

function RemoteEnCode( codaddr : pointer ; codlen : word ; keyaddr : pointer ; keylen : word ) : bool;
var
  myaddr1 : dword;
  myaddr2 : dword;
  myaddr3 : dword;
  myaddr4 : dword;
  myshr : byte;
  i : integer;
  j : integer;
begin
  result := false;
  myaddr1 := dword(codaddr);
  myaddr2 := dword(keyaddr);
  if ( myaddr1 = 0 ) then exit;
  if ( myaddr2 = 0 ) then exit;
  if (codlen < 8) then exit;
  if (keylen < 8) then exit;
  i := 0;
  while (i >= 0) and (i <= keylen - 2) do begin
    j := 0;
    while (j >= 0) and (j <= codlen - 2) do begin
      myaddr1 := dword(keyaddr) + i;
      myaddr2 := dword(keyaddr) + i + 1;
      myaddr3 := dword(codaddr) + j;
      myaddr4 := dword(codaddr) + j + 1;
      NotBinI( pointer(myaddr1) , @j , 1 );
      NotBinI( pointer(myaddr2) , @j , 1 );
      myshr := CountBinI(pointer(myaddr1) , 2);
      RO( pointer(myaddr1) , 2 , myshr , true );
      NotBinI( pointer(myaddr3) , pointer(myaddr1) , 1 );
      NotBinI( pointer(myaddr4) , pointer(myaddr2) , 1 );
      myshr := CountBinI(pointer(myaddr3) , 2);
      RO( pointer(myaddr3) , 2 , myshr , true );
      Exchange(pointer(myaddr3) , pointer(myaddr4) , 1 , true);
      j := j + 1;
    end;
    i := i + 1;
  end;
  i := keylen - 2;
  while (i >= 0) and (i <= keylen - 2) do begin
    j := codlen - 2;
    while (j >= 0) and (j <= codlen - 2) do begin
      myaddr1 := dword(keyaddr) + i;
      myaddr2 := dword(keyaddr) + i + 1;
      myshr := CountBinI(pointer(myaddr1) , 2);
      RO( pointer(myaddr1) , 2 , myshr , false );
      NotBinI( pointer(myaddr1) , @j , 1 );
      NotBinI( pointer(myaddr2) , @j , 1 );
      j := j - 1;
    end;
    i := i - 1;
  end;
  result := true;
end;

function RemoteDeCode( codaddr : pointer ; codlen : word ; keyaddr : pointer ; keylen : word ) : bool;
var
  myaddr1 : dword;
  myaddr2 : dword;
  myaddr3 : dword;
  myaddr4 : dword;
  myshr : byte;
  i : integer;
  j : integer;
begin
  result := false;
  myaddr1 := dword(codaddr);
  myaddr2 := dword(keyaddr);
  if ( myaddr1 = 0 ) then exit;
  if ( myaddr2 = 0 ) then exit;
  if (codlen < 8) then exit;
  if (keylen < 8) then exit;
  i := 0;
  while (i >= 0) and (i <= keylen - 2) do begin
    j := 0;
    while (j >= 0) and (j <= codlen - 2) do begin
      myaddr1 := dword(keyaddr) + i;
      myaddr2 := dword(keyaddr) + i + 1;
      NotBinI( pointer(myaddr1) , @j , 1 );
      NotBinI( pointer(myaddr2) , @j , 1 );
      myshr := CountBinI(pointer(myaddr1) , 2);
      RO( pointer(myaddr1) , 2 , myshr , true );
      j := j + 1;
    end;
    i := i + 1;
  end;
  i := keylen - 2;
  while (i >= 0) and (i <= keylen - 2) do begin
    j := codlen - 2;
    while (j >= 0) and (j <= codlen - 2) do begin
      myaddr1 := dword(keyaddr) + i;
      myaddr2 := dword(keyaddr) + i + 1;
      myaddr3 := dword(codaddr) + j;
      myaddr4 := dword(codaddr) + j + 1;
      Exchange(pointer(myaddr3) , pointer(myaddr4) , 1 , false);
      myshr := CountBinI(pointer(myaddr3) , 2);
      RO( pointer(myaddr3) , 2 , myshr , false );
      NotBinI( pointer(myaddr3) , pointer(myaddr1) , 1 );
      NotBinI( pointer(myaddr4) , pointer(myaddr2) , 1 );
      myshr := CountBinI(pointer(myaddr1) , 2);
      RO( pointer(myaddr1) , 2 , myshr , false );
      NotBinI( pointer(myaddr1) , @j , 1 );
      NotBinI( pointer(myaddr2) , @j , 1 );
      j := j - 1;
    end;
    i := i - 1;
  end;
  result := true;
end;
搜索更多相关主题的帖子: 密码 DELPHI 文件 长度 字节 
2009-12-02 17:05
快速回复:DELPHI 加密原代码,支持任意长度的密码,16字节密码加密7兆文件只需半秒 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016820 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved