1.前言
今天需要一个php写一个对ip进行加解密的算法,其中需要用到将ip转化为数字并对64位数字进行运算,网上找了一圈没找到,故打算用c++实现功能,通过php来调用,功能最终实现
2.代码片段
1.php部分(通过system调用外部程序并进行参数传递)
$allip = "";
for ($i = 0; $i < $count_json; $i++)
{
$nodes = $object[$i]->{'nodes'};
$count_nodes = count($nodes);
for ($j = 0; $j < $count_nodes; $j++)
$allip .= $nodes[$j];
}
$allip .= " ";
$allip .= $_COOKIE["userid"];
$command = 'dll.exe ' .escapeshellcmd($allip);
system($command);
2.c++部分(将解密后的东东写入文件中)
int main(int argc, char *argv[])
{
if (argc >= 3)
{
std::string strallip(argv[1]);
char pcExePath[MAX_PATH] = {0};
GetModuleFileNameA(NULL, pcExePath, MAX_PATH);
PathRemoveFileSpecA(pcExePath);
std::string strfilepath(pcExePath);
strfilepath += "/user/";
strfilepath += argv[2];
strfilepath += ".txt";
if (!strallip.empty() && strallip.size() % 12 == 0)
{
int ncount = strallip.size() / 12;
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
std::fstream desfile;
char szbuf[256] = {0};
desfile.open(strfilepath, std::ios_base::out);
for (int nindex = 0; nindex < ncount; ++nindex)
{
std::string strencip = strallip.substr(nindex * 12, 12);
desfile<<new_ip_decode(strencip)<<"\n";
}
desfile.close();
WSACleanup();
}
}
return 0;
}
3.备注
1.如何不通过文件,直接进行数据交换
2.如何实现调用c++库文件来实现数据交换
后续继续研究