我试图将一个包含160个元素的数组(“in”)内容复制到另一个数组(“temp”),其中有16个元素使用for循环。在每个循环中,一行将从160个元素数组中复制进入具有16个元素的新数组 我用这个但是不正确。
for ( int i = 0; i < ROWSS; i++)
{
std::array<unsigned char,16> temp = in[i*16];
功能:
InputDifferences(unsigned char * in, unsigned char * result,unsigned char * xi)
{
unsigned char yi[16];
unsigned char temp[160];
int index;
/for(int x=0 ; x<ROWS ; x++)
{
//unsigned char temp[160] = in[x*16];
//std::array<unsigned char,160> B = in;
for ( int i = 0; i < ROWSS; i++)
{
std::cout << "\nTables:\n";
for(int a = 1; a < ROUND; a++)
{
std::cout << "\nROUNDS:\n";
for (int j = 0; j < COLS; j++)
{
yi[i*COLS+j] = xi[i*COLS+j] ^ (a); //x (xor) 1,2,3.. and find input differences
index = temp[i*COLS+j] ^ temp[yi[i*COLS+j]]; // s(x) (xor) s(y) find output differences
result[a*16+index]++; // to find how many appears in each box
}
}
std::cout << "\nTry :" << i;
showMatrix2(result);
}
//} }
结果将是这样的
for i =0 temp[16] = in[0..15]
for i = 1 temp[16] = in[16..31]
等等 你能帮帮我吗?
答案 0 :(得分:0)
尝试:
//declare temp[16] outside for loop
for(int i=0;i<ROWSS;++i){
int j = 0;
while(j<16) temp[j] = in[j+i*16];
//the rest of your code
}
请注意,除非每次执行while循环时都创建一个新数组,否则temp []将被接下来的16个数字覆盖。