今天,我尝试将 xor 加密 java 代码转换为 c++ 但不起作用并输出错误,也许我错了,java 代码:
public static String encryptDecryptStr(String str) {
String key = "ABCDEF";
final int l0 = key.length() - 1;
int l1 = key.length() - 1;
final char[] strRemp = new char[str.length()];
char opcode = 85;;
for (int i = strRemp.length - 1; i >= 0; i--) {
strRemp[i] = (char) (str.charAt(i) ^ opcode ^ key.charAt(l1));
opcode = (char) ((char) (opcode ^ i ^ key.charAt(l1)) & 63);
--l1;
if (l1 < 0) l1 = l0;
}
return new String(strRemp);}
我尝试 C++ 代码:
JNIEXPORT jstring JNICALL Java_com_test_app_Utils_encryptDecryptStr(JNIEnv *env, jobject, jstring inStr){
std::string in = env->GetStringUTFChars(inStr, NULL);
std::string key = "ABCDEF";
int l0 = static_cast<int>(key.size() - 1);
int l1 = static_cast<int>(key.size() - 1);
char *strRemp = new char[in.size()];
char opcode = 85;
for (int i = static_cast<int>(strlen(strRemp) - 1); i >= 0; i--) {
strRemp[i] = in[i] ^ opcode ^ key[l1];
opcode = static_cast<char >(static_cast<char >(opcode ^ i ^ key[l1]) & 63);
--l1;
if (l1 < 0) l1 = l0;
}
return (jstring)env->NewStringUTF(strRemp);}
我测试:
com.test.app.Utils.encryptDecryptStr(encryptDecryptStr("Hello World"));
测试二:
encryptDecryptStr(com.test.app.Utils.encryptDecryptStr("Hello World"));
有人可以帮助我吗?
达令说
相关分类