Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

May be these lines of code will help you:

class Program {
    static void Main( string[ ] args ) {
      Dictionary< long, Tuple <input, output> > dict = new Dictionary<long,Tuple<input,output>> () ;
      for (long i = 0 ;  i < (long) (2^28) ;  i++) {
        input ip = new input( );
        output op = new output( );
        for( int j = 0; j < 8; j++ ) {
          //you have to write your own lodic for creating input and output
          unit isp = new unit( );
          unit osp = new unit( );
          ip.iData[ j ] = isp;
          op.oData[ j ] = osp;
        }
        dict.Add( i, Tuple.Create( ip, op ) );
      }    
    }
  }

  public class input {
    public  unit [] iData = new unit [8] ; 
  }

  public class output {
    public unit[ ] oData = new unit[ 8 ];
  }

  public class unit {
    public int item1;
    public int item2;
    public int item3;
  }

However this problem can be addressed in many ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top