首页 > C++字符串逆乘法问题

C++字符串逆乘法问题

简单明了,问题就是用字符串str1经过运算生成一个新的字符串str2

现在按照结果和运算过程去逆出最开始的那个字符串,有原始的运算过程
代码是可运行的 问题就是如何用str3倒出str1对应的那一串呢

这个只是一个代码片段 我单独提出来的

#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
//    e8353bb721210db274dfce41052f1232
    string str1 = "e;a60>9c1g2ce1531b67fe566;13619;";
    string str2;
    int key[6]={1,2,3,4,5,6};
    int keyCount = sizeof(key)/sizeof(int);
    int strCount = str1.length();
    for(int i = 0; i < strCount; i++){
        str2.append(1,str1[i]^(key[i%keyCount]));
    }
    cout<<str2<<endl;//-----d9b2588a2c7ed3674d75ea0079273789

    //由字符串e8353bb721210db274dfce41052f123算出   str1
    string str3("e8353bb721210db274dfce41052f1232");
    for(int i = 0; i < strCount; i++){
//        如何倒算出字符串str1的值
    }
    return 0;
}

异或加密的解密过程就是对加密后的字符串再进行一次异或,也就是说在把 str3 当成 str1 放到你的方法里走一遍即可。

不过也真是神奇,你这个算法把字符串异或后出来的字符串居然还可读,也是够绝。


楼上的意思是一个数和同一个数异或两次结果就是他本身:

std::string str3;
for (int i = 0; i < strCount; i++){
       str3.append(1,str2[i]^(key[i%keyCount]));
    }

这样str3就和str1一样了。

【热门文章】
【热门文章】