1

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.

Jimbo Jones
  • 983
  • 4
  • 13
  • 48
  • What is the question? Your loops seem to be correct ... – Aziz Dec 08 '16 at 01:16
  • if you look at the for loop in the image, it shows a dependency to two cipher text values, in there complete form, so the questain is how can one write a loop in the context of hex values – Jimbo Jones Dec 08 '16 at 01:20
  • You could look at the stuff inside the loop and figure out whether it depends on the order, or you could read the text surrounding the algorithm and it might tell you. – user253751 Dec 08 '16 at 02:35
  • Note `c1` is likely initialize as negative. Suggest using `unsigned long long`. – chux - Reinstate Monica Dec 08 '16 at 04:03

1 Answers1

2

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;
                        …
                    }
Armali
  • 18,255
  • 14
  • 57
  • 171