将c++函数转换为PHP
Convert c++ function to PHP?
我想将我的xor函数转换为PHP。这能做到吗?它需要像现在这样工作…
string encryptDecrypt(string toEncrypt) {
char key[9] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
string output = toEncrypt;
for (int i = 0; i < toEncrypt.size(); i++)
output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))];
return output;
}
您可以在PHP中使用与c++函数几乎相同的语法:
function encryptDecrypt($toEncrypt)
{
$key= array( '1', '2', '3', '4', '5', '6', '7', '8', '9' );
$key_len = count($key);
$output = $toEncrypt;
for ($i = 0; $i < strlen($toEncrypt); $i++)
{
$output[$i] = $toEncrypt[$i] ^ $key[$i % $key_len];
}
return $output;
}
c++函数在线演示:https://ideone.com/g9cpHJ
PHP函数的在线演示:https://ideone.com/3prgd0
在PHP中是这样的:
function encryptDecrypt($toEncrypt){
$key = array( '1', '2', '3', '4', '5', '6', '7', '8', '9' );
$output = $toEncrypt;
for ($i = 0; $i < strlen($toEncrypt); $i++)
$output = pow( $toEncrypt[$i], $key[$i % count($key)]; );
return $output; }
我希望一切顺利。
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 如何在PHPCPP库中将C++map<string,map<string>>转换为php::value?
- 如何将 ZVAL 转换为 PHP 扩展的矢量
- 将此 C 函数转换为 PHP
- 从 C++、C#、Perl 或 Java 转换为 PHP
- 将php代码转换为C(sha1算法)
- 将 vector<std::string> 转换为本机 PHP 数组
- 在Php - cpp中将Php::Object转换回c++对象
- 如何使用CURL将这样的PHP代码转换为C/ c++
- 将C++代码转换为PHP
- 将c++函数转换为PHP