将密文分成子串(vigenere密码)
splitting up cipher text into substrings (vigenere cipher)
我正在尝试实现一种算法,该算法将猜测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)
等等
有什么想法吗?
更新
我现在已经尝试实现我自己的代码,下面是我所做的:
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();
}
}
}
正如我在下面提到的,我的输出只反映基于在第一个字符上(即,如果密钥长度为2,而不是2、4、6、8、10…,则为1、3、5、7、9)
未测试,但您可以执行以下操作:
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
}
相关文章:
- c++中的oop(密码生成)
- 密码登录程序将永远循环并显示不正确的结果
- OpenSSL没有共享密码
- Cryptopp:获取密码输入的填充字符串
- 密码长度验证 (c++)
- C++ win32 如何使密码字段可选并启用复制和粘贴?
- 仿射密码解密,输出大小写不同
- 替换密码:哪一个?
- 无法使用 openssl 服务器,因为密码已过时...什么的...ERR_SSL_VERSION_OR_CIPHER_MISMATCH
- 如何使用 c++ 在 sqlite3 中打开受密码保护的数据库?
- 根据用户名和密码 Qt C++重新访问数据库值
- C++密码问题
- 无法在 Cocos2dx 中使用受密码保护的 zip 文件
- 如何使用librdkafka设置明文协议(无SASL)的用户名和密码?
- 如何将凯撒密码的元素从字符串更改为字符串
- Vigenere密码的C++功能有时才起作用(适用于某些输入,跳过其他输入的班次)
- Vigenere密码使用命令行提示
- C 链接列表Caesar Cipher Vigenere密码
- 将密文分成子串(vigenere密码)
- 自制Vigenere密码;使用acsii字符操作