兄弟姐妹们,帮帮忙,将下面这两个C++函数转换为delphi的过程。谢谢!(100分)

  • 主题发起人 主题发起人 gaoyongming
  • 开始时间 开始时间
G

gaoyongming

Unregistered / Unconfirmed
GUEST, unregistred user!
void cipher_str(char * cipher,int length, unsigned char * passwd)
/*将长度为length*2的字符串转换为16进制串*/
{
int i, k1, k2;
char hex[3], chmap[17]="0123456789abcdef";
memset(passwd,0,length);
for( i = 0; i < length; i++ )
{
hex[0] = cipher[i*2];
hex[1] = cipher[i*2+1];
for( k1=0; k1<16; k1++ )
if( chmap[k1]==hex[0] )
break;
for( k2=0; k2<16; k2++ )
if( chmap[k2]==hex[1] )
break;
*(passwd+i)= (unsigned char)(k1*16+k2);
}
*(passwd+i)='/0';
}
void chg_cip(unsigned char * passwd, int length)
/*口令加密*/
{
int i;
unsigned char temp;
for( i = 0; i < length; i++)
{
temp = 0;
passwd = ~passwd;
temp = passwd;
passwd = passwd/16;
temp = temp & 0x0f;
temp = temp*16;
passwd = temp + passwd;
}
}

将上面两个C++函数转换为delphi的过程!谢谢
 
procedure cipher_str(cipher : PChar;length: Integer; passwd: PByte);
var
i, k1, k2: Integer;
pwd : PChar;
hex: array[0..2] of char;
chmap: array[0..16] of char;
begin
chmap := '0123456789abcdef';
FillChar(passwd,0, length);
pwd := PChar(passwd);
for i := 0 to length - 1 do begin
hex[0] := cipher[i * 2];
hex[1] := cipher[i *2 + 1];
for k1:= 0 to 15 do begin
if chmap[k1] = hex[0] then break;
for k2 := 0 to 15 do begin
if chmap[k2] = hex[0] then break;
end;
end;
//(pwd + i)^ := Chr(k1 * 16 + k2);
Byte((pwd + i)^) := Byte(k1 * 16 + k2);
end;
(pwd + i)^ := #0;
end;

procedure chg_cip(passwd: PByte; Length: Integer);
var
i : Integer;
temp: Byte;
pwd : PChar;
begin
pwd := PChar(passwd);
for i := 0 to length - 1 do begin
temp := 0;
Byte(pwd) := not Byte(pwd);
temp := Byte(pwd);
Byte(pwd) := Byte(pwd) div 16;
temp := temp and $0F;
temp := temp *16;
Byte(pwd) := temp + Byte(pwd);
end;
end;

不怎么熟悉,编译好像过了[:D][:D]
 
后退
顶部