Hi I have a small program that takes a 10bit key, compresses it into 8bit key and does a left shift 8times, generating a key each time. I am using a one dimensional array to store the key value of each round. the probelm is that the next round over writes the key values. My code is as follows:

#include <iostream.h>
#include <stdlib.h>

int main()

    int cipherKey[10] = {1,0,1,0,0,1,0,1,0,0};
    int compression_P_box[8]= {4,10,6,3,8,2,1,7};
    int block[8];
    cout << "Compressed Key: ";
    for (int i=0; i<8; i++)
       block[i] = cipherKey[compression_P_box[i]-1];
       cout << block[i] << " ";
    cout << endl<<endl;   
    cout << "Round Key:" << endl;
    for (int j=0; j<8; j++)
       int temp[8];
       temp[j] = block[0];
       for (int k=1; k<=8; k++)
         block[k-1] = block[k];
         block[8] = temp[j];
         cout << block[k] << " " ;
       cout << endl;
    cout << endl;

      return 0;

I want to store the values in a two dimensional array. Any help would be appreciated.

7 Years
Discussion Span
Last Post by Nemo_NIIT
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.