Показать сообщение отдельно
Старый 23.09.2004, 18:36   #1  
Lihgt is offline
Lihgt
Участник
 
48 / 70 (3) ++++
Регистрация: 16.04.2002
Адрес: Москва
Функция похожая на buildPassword
Один мой знакомый написал функцию, которая выполняет операцию аналогичную аксаптовской bildPassword.
Очень пригодилась для коннекта с терминалов с аксаптовским логином и паролем.
PHP код:
function Str2Int(_Str String) : Integer;
var
  
tmpCode Int64;
  
tmpChar Integer;
  
i       Integer;
begin
  _Str 
:= AnsiLowerCase(_Str);
  
tmpCode := $015A4E35;
  
:= 1;
  While 
<= Length(_Str) Do
  
Begin
    tmpChar 
:= Ord(_Str[i]) and $0FF;

    
tmpCode := tmpCode and $FFFFFFFF;
    
tmpCode := ((tmpCode shl 13) and $0FFFFE000) +
               ((
tmpCode shr 19) and $000001FFF);
    
tmpCode := tmpCode xor ((tmpChar shl 5) and $01FE0);
    
tmpCode := (tmpCode xor tmpChar) + 3;
    
Inc(i);
  
End;

  
Result := tmpCode and $FFFFFFFF;
end;

function 
Int2Code(intCode Integer) : String;
var
  
tmpCode Int64;
  
tmpByte Shortint;
  
Code    String;
  
i       Integer;
begin
  tmpCode 
:= intCode and $FFFFFFFF;
  
:= 0;
  While 
Do
  
Begin
    tmpByte 
:= tmpCode mod $24;
    If 
tmpByte 10 Then
      Code 
:= Chr(Ord('0') + tmpByte) + Code
    
Else
      
Code := Chr(Ord('A') + tmpByte 10) + Code;

    
tmpCode := (tmpCode * $38E38E39shr 3;
    
tmpCode := (tmpCode and $FFFFFFFF00000000shr 32;
    
Inc(i);
  
End;

  
Result := Code;
end;

function 
CryptUserPass(Password PCharUser PChar) : PCharstdcall;
var
  
Code     String;
  
tmpCode  Integer;
  
tmpConst Integer;
begin
  tmpConst 
:= $A59C29F1;

  
tmpCode  := Str2Int(String(User) + String(Password)) xor tmpConst;
  
Code := Int2Code(tmpCode);

  
tmpConst := ($928379A1 tmpCode) and $FFFFFFFF;

  
tmpCode := Str2Int(String(Password)) xor tmpConst;
  
Code := Code Int2Code(tmpCode);

  
Result := PChar(Code);
end