1

嗨,我厌倦了用 DES 实现 CFB。我想我可以使用 CFB 进行加密,但我该如何解密?我的主要问题是使用 CFB 正确加密的 CFB 代码??。由于我的限制,我无法使用其他库。

for (int i = 0; i < VecMSG.size(); i++) {
DESEncrypt(IV, Key);

stringstream str;
str << bitset < 32 > (V[0]); //First 32 bits convert to string
str << bitset < 32 > (V[1]); //Second 32 bits covert to string and join with the first
VText2 = VText = str.str(); //Store in 2 different strings
VText = VText.substr(0, 5); //Take the most significant first 5 bits in the form of 
str.str("");

bitset < 2 > mybits(VText); //covert to bits
bitset < 2 > mybits2(VecMSG[i]); //covert plaintext bits from string to bits
str << (mybits ^= mybits2); //XOR with and convert to string
VecCipher.push_back(str.str()); //Store in a different vector
str.str("");
VText2 = VText2.substr(5) + VecCipher[i]; //Remove the first 5 bits and join ciphertext to the end
V[0] = (unsigned int)VText2.substr(0,32).c_str();
V[1] = (unsigned int)VText2.substr(32).c_str();

}

4

0 回答 0