Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;向字符串中添加空格_C++_Encryption_Block Cipher_Letter Spacing - Fatal编程技术网

C++ C++;向字符串中添加空格

C++ C++;向字符串中添加空格,c++,encryption,block-cipher,letter-spacing,C++,Encryption,Block Cipher,Letter Spacing,例如,我有一个密码文本代码“KWSVSYXKSBOKKBNRKDKXNKNBEXUKBOKDKLKBGRO”我对它进行了一些频率分析计算,并开始反向工程来破解密码 我的密码是 “带密钥的新已解决密码文本是:amillionaireahardhatandadukeareatabarwhent” 现在唯一的问题是,我不知道如何正确地在单词之间加空格,这样就可以更英语一些了“百万富翁戴安全帽和醉汉是……” 下面是我破解密码的密码 string cipher = ""; int i = 0,

例如,我有一个密码文本代码“KWSVSYXKSBOKKBNRKDKXNKNBEXUKBOKDKLKBGRO”我对它进行了一些频率分析计算,并开始反向工程来破解密码

我的密码是


“带密钥的新已解决密码文本是:amillionaireahardhatandadukeareatabarwhent”

现在唯一的问题是,我不知道如何正确地在单词之间加空格,这样就可以更英语一些了
“百万富翁戴安全帽和醉汉是……”

下面是我破解密码的密码

string cipher = "";
    int i = 0, alphabet[26] = { 0 }, j, temp;
    int n = cipher.length();
    // declaring character array 
    char char_array[343];
    // copying the contents of the 
    // string to char array 
    strcpy_s(char_array, cipher.c_str());

    //print the entire cipher text and ASCII value
    //for (int i = 0; i < n; i++)
    //{ 
        //cout << char_array[i] << endl;
    //  cout << "the ASCII value of " << char_array[i] << " is " << int(char_array[i])  << endl;
    //  }


    //Find the most frequent letter in the cipher text
    while (char_array[i] != '\0') {

        if (char_array[i] >= 'A' && char_array[i] <= 'Z') {
            j = char_array[i] - 'A';
            ++alphabet[j];
        }

        ++i;
    }
    cout << "Frequency of all alphabets in the string is:" << endl;

    for (i = 0; i < 26; i++)
        cout << char(i + 'A') << " : " << alphabet[i] << endl;
    //end most frequent
    cout << endl;

    const int N = sizeof(alphabet) / sizeof(int);

    for (i = 0; i < 26; i++){


        cout << "Most frequent letter is : " << char(distance(alphabet, max_element(alphabet, alphabet + N)) + 'A') << " trying key : " << distance(alphabet, max_element(alphabet, alphabet + N)) << endl;
        //cout << alphabet[i] << "Most frequent position of key is trying: " << distance(alphabet, max_element(alphabet, alphabet + N)) << endl;
        cout << "New solved cipherr text with key is : " << encrypt(char_array, distance(alphabet, max_element(alphabet, alphabet + N))) << endl << endl;

        alphabet[distance(alphabet, max_element(alphabet, alphabet + N))] = 0;
    }

string encrypt(string text, int s)
{
    string result = "";

    // traverse text 
    for (int i = 0; i<text.length(); i++)
    {
        // apply transformation to each character 
        // Encrypt Uppercase letters 
        result += char(int(text[i] + s - 65) % 26 + 65);
    }

    // Return the resulting string 
    return result;
}
字符串密码=”;
int i=0,字母[26]={0},j,temp;
int n=cipher.length();
//声明字符数组
字符数组[343];
//复制
//字符串到字符数组
strcpy_s(字符数组,cipher.c_str());
//打印整个密码文本和ASCII值
//对于(int i=0;i//cout我能想到的唯一解决方案是使用某种英语词典,检查每个字符,直到它看到一个单词,然后在那里放一个空格。例如,这个解决方案中的问题是一个单词,像and,它可以是a或or and。因此无法确定在哪里放一个空格。可能是一个非常复杂的AI根据之前看到的单词确定下一个单词的算法。

要使用算法将文本无空格拆分为单词吗?在编码过程中,除了大写字母A到Z之外,您可以忽略任何内容。您无法解码在编码步骤中丢弃的信息。避免使用神奇的数字,如
65
,请使用
'A'
instead。(顺便说一句,A-Z范围不保证连续)听起来你还需要对空格进行编码。你需要在可能的替换中添加第27个字符。这对ASCII字符的数学来说很难,但如果你创建自己的替换字符数组,就很容易了。@jarod42,不。使用空格拆分文本这是我的想法。手动输入常用单词,让它在他发短信说,这个项目不够大,无法在其中实现任何人工智能,不过还是要谢谢你