473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Converting one dimensional array into two dimensional array

19
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:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7.     int cipherKey[10] = {1,0,1,0,0,1,0,1,0,0};
  8.     int compression_P_box[8]= {4,10,6,3,8,2,1,7};
  9.     int block[8];
  10.     int key[8][8];
  11.     cout << "Compressed Key: ";
  12.     for (int i=0; i<8; i++)
  13.     {
  14.        block[i] = cipherKey[compression_P_box[i]-1];
  15.        cout << block[i] << " ";
  16.     }
  17.     cout << endl<<endl;   
  18.     cout << "Round Key:" << endl;
  19.     for (int j=0; j<8; j++)
  20.     {
  21.        int temp[8];
  22.        temp[j] = block[0];
  23.        for (int k=1; k<=8; k++)
  24.        {
  25.          block[k-1] = block[k];
  26.          block[8] = temp[j];
  27.          cout << block[k] << " " ;
  28.        }
  29.        cout << endl;
  30.     }
  31.     cout << endl;
  32.  
  33.       system("PAUSE");
  34.       return 0;
  35. }

I want to store the values in a two dimensional array. Any help would be appreciated.
Oct 5 '10 #1
1 5105
Oralloy
988 Expert 512MB
I assume you want to populate your [b]key[8][8][b] array at the top of the j loop starting at line 19?

Where j is the key round?

If so, you might try inserting this right after line 20
Expand|Select|Wrap|Line Numbers
  1.   for (int bit = 0;  (8 > bit);  bit ++)
  2.     key[j][bit] = block[bit];
  3.  
Also, there's a really good essay on arrays at this C topic: http://bytes.com/topic/c/insights/77...rrays-revealed

Good luck!
Oct 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Bob Bedford | last post by:
I've this structure in a XML file: Type Model Detail Datas Datas Datas Datas /Detail Detail
12
by: JKop | last post by:
template<class T> inline T& NthArrayMember( T & (array),size_t i) { return array; } template<class T> inline const T& NthArrayMember( const T & (array),size_t i) { return array;
4
by: Bob Bedford | last post by:
I've to save in an array of array some values. Problem: I don't know the size of the array before filling it. I'd like something like $bigarray = array(): then runnig the code I must...
7
by: Eric Boutin | last post by:
Hi ! I would like to generate an array of type char; I just dont really figure out how I could do it with malloc or calloc.. I mean.. I know how to allocate a simple array with both of them;...
4
by: Svetoslav Vasilev | last post by:
Hi, I experience some troubles trying to convert an object,returned by a DataTable for a field value to its actual representation of Byte. The field values in a DataTable as we all know are returned...
10
by: Steve | last post by:
this code: private Array m_arrays = new Array; results in an array of 3 null Array objects. What am I missing?
3
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; ...
2
by: Kenneth Brody | last post by:
Given the following current definition: int array; Is the following equivalent? (By "equivalent", I mean that any reference to "array" retains the same meaning, and that the memory layout...
8
by: =?big5?B?r0W84Q==?= | last post by:
Hi All C gurus: Below is a small program to print out the address of array and address of array variable: int main() { char array = "haha"; printf("array:%x\n", array); printf("&array:%x\n",...
4
by: Bob Bedford | last post by:
Hello, I've an array of array(1,2,3,4). I'd like to retrieve the values in 3 and 4 giving the values 1 and 2. How can I do that, how to search in an array of array ? in short, how to write the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.