Search code examples
c#binarycryptanalysis

generating 2^24 tables which differ only at one bit with c#


These days, I am working in the field of cryptanalysis and have started to do programming with C#

Now,
For finding the 5 optimal s-boxes(i mean those 2^24 tables), they should be generated, first.I know everything about the criteria for finding the optimal ones.

Here, a sbox is 2*8 table which the first row include the numbers between 0-7(binary:000 - 111)(as sbox input) and in the second row, every input(0 - 7) is associated with a number,as below:

The first sbox:

input     000   001 010 011 100 101 110 111  
output    000   000 000 000 000 000 000 000  

The second sbox which differs only at one bit:

input   000 001 010 011 100 101 110 111  
output  001 000 000 000 000 000 000 000  

The Third one which differs only at one bit coparing to the second one:

input   000 001 010 011 100 101 110 111  
output  010 000 000 000 000 000 000 000  

and the 2^24-th one:

input   000 001 010 011 100 101 110 111  
output  111 111 111 111 111 111 111 111  

Question is how to generate these tables? i don't know how to put for loop or save the results in array separately for each sbox.

Any help is appreciated.


Solution

  • for (int j = 0; j < Math.Pow(2, 24); j++)
      {
               Console.WriteLine(Convert.ToString(j, 2).PadRight(24, '0'));
      }