calgorithmfor-loopcryptographycryptanalysis

Loop in an algorithm which is dependent on hex value


I am only learning c and I am trying to implement a for loop from an algorithm. I am so so confused in how to implement it, please see my attempt below. Any help or thoughts would be greatly appreciated, it implies a loop within a loop which has a dependency to hex value. It has come from an Differential Cryptanalysis algorithm.

the loop as stated in algorithm is :

enter image description here

enter image description here

ciphertext C0 = (L0,R0) ciphertext C1 = (L1,R1)

Where

                long long c0 = 0x78661EB54FE76763;
                long long c1 = 0x98D9EC2327F1BF03;

My attempt so far

                long long c0 = 0x78661EB54FE76763;
                long long c1 = 0x98D9EC2327F1BF03;

                for (int c0 = 0; c0 <= 0xff; c0++)
                {
                    for (int c1 = 0; c1 <= 0xff; c1++)
                    {
                    }
                }

But I dont know how to handle the depenacy to hex values. Its is latter ordering: (0, 0), (0, 1), (1, 2), ..., (0, 255), (1, 0), …

So it means all possible combinations - the ordering does not matter so long as you go through them all.


Solution

  • Lack of context made it difficult to understand your question. Looking at it reveals that the problem lies in D = (c0, a0 ⊕ c0, a1 ⊕ c1, c1), i. e. you need to know how to make a 32-bit value out of a 4-tuple of 8-bit values. This can be done simply by shifting the values to the corresponding positions:

                    for (int c0 = 0; c0 <= 0xff; c0++)
                        for (int c1 = 0; c1 <= 0xff; c1++)
                        {
                            uint32_t D = c0<<24|(a0^c0)<<16|(a1^c1)<<8|c1;
                            …
                        }