lundi 11 octobre 2021

Circular left shift for DES algorithm

I am a student and writing a program to encrypt and decrypt a message, I am having some trouble with my left shift function. Instead of shifting the first value it is deleting the last value. (ignore the cout statement that was just me checking to see the value of leftS)

The input is "0001001100110100010101110111100110011011101111001101111111110001"

Once it is split in half I get c0=1111000011001100101010101111 and d0=0101010101100110011110001111 with the left shift c0 is expected to be 1110000110011001010101011111 but I am instead getting 111100001100110010101010111

std::string Key::leftShift (std::string key) {
  std::string leftS = " ";
  for (int k = 1; k < 28; k++) {
      leftS += key[k];
    }
    leftS += key[0];
  std::cout << leftS << std::endl;
  return leftS;
}

Aucun commentaire:

Enregistrer un commentaire