www.pudn.com > SPYQQ3.rar > Encode.pas


unit Encode; 
 
interface 
 
function  Encrypt(const str: string): string; 
function  Decrypt(const str: string): string; 
 
implementation 
 
{#### 加密解密} 
const 
  fSeedA = 56789;///     常量   , 
  fSeedB = 54667;   ///     常量   , 
  fKey   = 1006;     //     钥匙 
function  Encrypt(const str: string): string; 
var 
      i, j, iKey: Integer; 
      strGet: string; 
begin 
      strGet := str; 
      iKey   := FKey; 
      Result := strGet; 
      for i := 1 to Length(strGet) do 
      begin    
          Result[i] := Char(byte(strGet[i])xor(iKey shr 8)); 
          iKey := (Byte(Result[I]) + iKey) * FSeedA + FSeedB; 
      end;    
      strGet := Result; 
      Result := ''; 
      for i:=1 to Length(strGet) do 
      begin    
          j := Integer(strGet[i]); 
          Result := Result + Char(65+(j div 26))+ char(65+(j mod 26));    
      end;    
end; 
 
function Decrypt(const str: string): string; 
  var    
      i, j, iKey: Integer; 
      strGet: string; 
  begin    
      strGet := str; 
      iKey   := FKey; 
      Result := ''; 
      for i := 1 to (Length(strGet) div 2) do 
      begin    
          j := (Integer(strGet[2*i-1])-65)*26; 
          j := j + (Integer(strGet[2*i])-65); 
          Result := Result + Char(j); 
      end;    
      strGet := Result; 
      for i := 1 to Length(strGet) do 
      begin    
          Result[i] := Char(byte(strGet[I]) xor (iKey shr 8)); 
          iKey := (Byte(strGet[I]) + iKey) * FSeedA + FSeedB;    
      end;    
end; 
{#############} 
 
end.