【问题标题】:generating 2^24 tables which differ only at one bit with c#生成 2^24 个表,这些表与 c# 仅相差一位
【发布时间】:2013-07-16 11:46:35
【问题描述】:

这些天,我在密码分析领域工作,并开始使用C#进行编程

现在,
为了找到 5 个最佳 s-box(我的意思是那些 2^24 个表),首先应该生成它们。我知道关于找到最佳的标准的一切。

这里,一个 sbox 是 2*8 表,第一行包含 0-7(binary:000 - 111)(as sbox input) 和在第二行中,每个输入(0 - 7)都与一个数字相关联,如下所示:

第一个 sbox:

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

只有一点不同的第二个 sbox:

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

第三个与第二个相比只有一点不同:

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

和第 2^24 个:

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

问题是如何生成这些表?我不知道如何为每个 sbox 放置 for 循环 或将结果分别保存在数组中。

感谢任何帮助。

【问题讨论】:

    标签: c# binary cryptanalysis


    【解决方案1】:

    这些代码行可能会对你有所帮助:

    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;
      }
    

    然而,这个问题可以通过多种方式解决。

    【讨论】:

    • 谢谢。输入是固定的,数字在 0-7 之间。问题正是“如何产生输出”?如何更改一位?如何前进?再次感谢您。
    • 我想,你知道如何生成数据并且你有与循环相关的问题。如果我能帮助你,我会努力的。
    • 对不起,我不能完全理解你。如果您能找到解决方案,请在此处发布。看到会很有趣......
    • 让我解释一下。总共有 2^24 个表,输入行是固定的。只有 output 发生变化,并且与前一个相比只有一位。我不知道该怎么做。
    • 例如上面的表1和表2只有一位输出不同
    【解决方案2】:
    for (int j = 0; j < Math.Pow(2, 24); j++)
      {
               Console.WriteLine(Convert.ToString(j, 2).PadRight(24, '0'));
      }  
    

    【讨论】:

    • 我们可以使用 16777216 代替 Math.Pow(2,24)
    • 这并不重要。应该生成所有排列。
    猜你喜欢
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多