C++ 将密文拆分为子字符串(vigenere密码)

C++ 将密文拆分为子字符串(vigenere密码),c++,algorithm,encryption,vigenere,C++,Algorithm,Encryption,Vigenere,我正在尝试实现一个算法,该算法将猜测vigenere密码的关键字的可能密钥长度 我正在着手寻找每种可能的密钥长度的一致性索引,但我无法找到将密文拆分为子字符串的方法 也就是说,我想用这样的密码文本 ERTEQSDFPQKCJAORIJARTARTAAFIHGNAPROEOHAGJEOIHJA(这是随机文本,这里没有编码消息) 并将其拆分为不同的字符串,如下所示: key length 2: ETQDP... (every second letter starting from position

我正在尝试实现一个算法,该算法将猜测vigenere密码的关键字的可能密钥长度

我正在着手寻找每种可能的密钥长度的一致性索引,但我无法找到将密文拆分为子字符串的方法

也就是说,我想用这样的密码文本

ERTEQSDFPQKCJAORIJARTARTAAFIHGNAPROEOHAGJEOIHJA
(这是随机文本,这里没有编码消息)

并将其拆分为不同的字符串,如下所示:

key length 2: ETQDP... (every second letter starting from position 0)
              RESFQ... (every second letter starting from position 1)

key length 3: EEDQ.... (every third letter starting from position 0)
int len = cipherText.length;
char[] text2inspect = char[(len/keyLength) + 1]
for (int startIndex = 0; keyLength > startIndex; startIndex++){
  int destIndex = 0;
  for (int index = startIndex; len > index; index += keyLength){
    text2inspect[destIndex++] = cipherText[index];
  }
  text2inspect[destIndex] = 0; // String termination

  // add your inspection code here

}
等等

有什么想法吗

更新

我现在已经尝试实现自己的代码,下面是我所做的:

void findKeyLength(string textToTest)
{
size_t length = textToTest.length();
vector<char> vectorTextChar;
    //keeping key length to half the size of ciphertext; should be reasonable
for (size_t keylength = 1; keylength < length / 2; keylength++)
{
    for (size_t i = keylength; i < keylength ; i++)
    {   
        string subString = "";
        for (size_t k = i; k < length; k+=i)
        {
            vectorTextChar.push_back(textToTest[k]);
        }

        for (vector<char>::iterator it= vectorTextChar.begin(); it!=vectorTextChar.end(); ++it)
        {
            subString += *it;
        }
        cout << subString << endl; //just to see what it looks like
        cout << "Key Length : " << keylength << "IC: " << indexOfCoincidence(subString) << endl;
        vectorTextChar.clear();
    }
}
}
void findKeyLength(字符串textToTest)
{
size_t length=textToTest.length();
向量向量文本字符;
//将密钥长度保持在密文大小的一半;应该是合理的
对于(大小\u t键长度=1;键长度<长度/2;键长度++)
{
对于(size\u t i=keylength;i不能未测试,但您可以执行以下操作:

key length 2: ETQDP... (every second letter starting from position 0)
              RESFQ... (every second letter starting from position 1)

key length 3: EEDQ.... (every third letter starting from position 0)
int len = cipherText.length;
char[] text2inspect = char[(len/keyLength) + 1]
for (int startIndex = 0; keyLength > startIndex; startIndex++){
  int destIndex = 0;
  for (int index = startIndex; len > index; index += keyLength){
    text2inspect[destIndex++] = cipherText[index];
  }
  text2inspect[destIndex] = 0; // String termination

  // add your inspection code here

}