那位高手帮忙把C++翻译成DELPHI啊,谢谢了 ( 积分: 29 )

  • 主题发起人 主题发起人 冬月
  • 开始时间 开始时间

冬月

Unregistered / Unconfirmed
GUEST, unregistred user!
int L1PacketCore::Initial(DWORD skey)
{
BYTE key[8];
DWORD *pdata=(DWORD *)key;
pdata[0]=skey;
pdata[1]=0x930fd7e2;
blowFish.Initialize(key,8);
DWORD *pKey=(DWORD *)m_SSendKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
pKey=(DWORD *)m_SRecvKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
pKey=(DWORD *)m_CSendKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
pKey=(DWORD *)m_CRecvKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
return 1;
}
void L1PacketCore::EnCode(BYTE* Sdata, int len, BYTE* key)
{
Sdata[0] = Sdata[0]^key[0];
for(int i = 1;i<len;i++)
Sdata = Sdata^ Sdata[i-1] ^ key[i&amp;7];
Sdata[3] = Sdata[3]^key[2];
Sdata[2] = Sdata[2]^Sdata[3]^key[3];
Sdata[1] = Sdata[1]^Sdata[2]^key[4];
Sdata[0] = Sdata[0]^Sdata[1]^key[5];
}
void L1PacketCore::UnCode(BYTE* Sdata, int len, BYTE* key)
{
int count=len-1;
Sdata[0] = Sdata[0]^Sdata[1]^key[5];
Sdata[1] = Sdata[1]^Sdata[2]^key[4];
Sdata[2] = Sdata[2]^Sdata[3]^key[3];
Sdata[3] = Sdata[3]^key[2];
for(int i = count;i>0;i--)
Sdata = Sdata^ Sdata[i-1] ^ key[i&amp;7];
Sdata[0] = Sdata[0]^key[0];
}

int L1PacketCore::OnUnS2C(BYTE* SData, int len)
{
UnCode(SData,len,m_CRecvKey);
DWORD *pData=(DWORD *)SData;
DWORD *pKey=(DWORD *)m_CRecvKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;

EnCode(SData,len,m_SSendKey);
pKey=(DWORD *)m_SSendKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;
return 0;
}

int L1PacketCore::OnUnC2S(BYTE* SData, int len)
{
UnCode(SData,len,m_SRecvKey);
DWORD *pData=(DWORD *)SData;
DWORD *pKey=(DWORD *)m_SRecvKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;
EnCode(SData,len,m_CSendKey);
pKey=(DWORD *)m_CSendKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;
return 0;
}
 
int L1PacketCore::Initial(DWORD skey)
{
BYTE key[8];
DWORD *pdata=(DWORD *)key;
pdata[0]=skey;
pdata[1]=0x930fd7e2;
blowFish.Initialize(key,8);
DWORD *pKey=(DWORD *)m_SSendKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
pKey=(DWORD *)m_SRecvKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
pKey=(DWORD *)m_CSendKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
pKey=(DWORD *)m_CRecvKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
return 1;
}
void L1PacketCore::EnCode(BYTE* Sdata, int len, BYTE* key)
{
Sdata[0] = Sdata[0]^key[0];
for(int i = 1;i<len;i++)
Sdata = Sdata^ Sdata[i-1] ^ key[i&amp;7];
Sdata[3] = Sdata[3]^key[2];
Sdata[2] = Sdata[2]^Sdata[3]^key[3];
Sdata[1] = Sdata[1]^Sdata[2]^key[4];
Sdata[0] = Sdata[0]^Sdata[1]^key[5];
}
void L1PacketCore::UnCode(BYTE* Sdata, int len, BYTE* key)
{
int count=len-1;
Sdata[0] = Sdata[0]^Sdata[1]^key[5];
Sdata[1] = Sdata[1]^Sdata[2]^key[4];
Sdata[2] = Sdata[2]^Sdata[3]^key[3];
Sdata[3] = Sdata[3]^key[2];
for(int i = count;i>0;i--)
Sdata = Sdata^ Sdata[i-1] ^ key[i&amp;7];
Sdata[0] = Sdata[0]^key[0];
}

int L1PacketCore::OnUnS2C(BYTE* SData, int len)
{
UnCode(SData,len,m_CRecvKey);
DWORD *pData=(DWORD *)SData;
DWORD *pKey=(DWORD *)m_CRecvKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;

EnCode(SData,len,m_SSendKey);
pKey=(DWORD *)m_SSendKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;
return 0;
}

int L1PacketCore::OnUnC2S(BYTE* SData, int len)
{
UnCode(SData,len,m_SRecvKey);
DWORD *pData=(DWORD *)SData;
DWORD *pKey=(DWORD *)m_SRecvKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;
EnCode(SData,len,m_CSendKey);
pKey=(DWORD *)m_CSendKey;
pKey[0]^=*pData;
pKey[1]+=0x287EFFC3;
return 0;
}
 
先翻译一个函数:
int L1PacketCore::Initial(DWORD skey)
function L1PacketCore.Initial(skey: DWORD): Integer;
var
key: array [0..7] of byte;
pdata, pKey: PIntegerArray;
begin
pdata := @key;
pdata[0] := skey;
pdata[1] := $930fd7e2;
blowFish.Initialize(key, 8);
pKey := @m_SSendKey;
pKey[0] := pdata[0];
pKey[1] := pdata[1];
pKey := @m_SRecvKey;
pKey[0] := pdata[0];
pKey[1] := pdata[1];
pKey := @m_CSendKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
pKey=@m_CRecvKey;
pKey[0]=pdata[0];
pKey[1]=pdata[1];
result := 1;
end;
 
function L1PacketCore::OnUnC2S( SData: PByte, len: Integer): Integer;
type
PDWOrd = ^DWord;
var
pData, pKey: PDWord;
begin
UnCode(SData,len,m_SRecvKey);
pData:=PDWORD(SData);
pKey:=PDWORD(m_SRecvKey);
pKey[0]:= Power(pKey[0], @pData);
pKey[1] := pKey[1] + $287EFFC3;
EnCode(SData,len,m_CSendKey);
pKey:=PDWORD(m_CSendKey);
pKey[0]:= Power(pKey[0], @pData);
pKey[1] := pKey[1] + $287EFFC3;
Result := 0;
end;

凑个热闹,仅供参考,其他应该差不多
 
这么简单得都可以用翻译工具直接翻译,
建议楼主熟悉一下c/c++
 
我也正找呢,楼上推荐一个
 
后退
顶部