Exemple #1
0
        public static int SearchLastNotEmptyLayer(SPNetWay Way)
        {
            int index = -1;

            for (int i = 0; i < Way.layers.Count; i++)
            {
                int input_sum = 0;
                if (Way.layers[i].blocks != null)
                {
                    foreach (var block in Way.layers[i].blocks)
                    {
                        if (block.active_inputs != null)
                        {
                            foreach (var input in block.active_inputs)
                            {
                                input_sum += Convert.ToInt32(input);
                            }
                        }
                    }
                }
                if (input_sum == 0)
                {
                    index = i - 1;
                    break;
                }
            }
            return(index);
        }
 public SolverParams(SPNetWay Way, ISPNet Net, AnalisysType Type, int MaxActiveBlocksOnLayer)
 {
     this.Net  = Net;
     this.Type = Type;
     this.Way  = Way;
     this.P    = new Prevalence(0, 0, Net.GetSettings().SBoxSize);
     this.MaxActiveBlocksOnLayer = MaxActiveBlocksOnLayer;
     this.BIndex = -1;
     this.lastNotEmptyLayerIndex = -1;
 }
Exemple #3
0
 public void Init(TaskerParams Params)
 {
     this.Params          = Params;
     _rounds_count        = Params.Net.GetLayers().Count / 3;
     _tempEmptyWay        = WayConverter.ToWay(Params.Net);
     IsBruteForceTurnedOn = false;
     Iter   = new InputsIterator(Params.Net.GetSettings().SBoxCount, Params.Net.GetSettings().SBoxSize);
     _tasks = new ConcurrentQueue <Task>();
     InitSolvers();
     ProcessRules();
 }
Exemple #4
0
        public static SPNetWay ToWay(ISPNet Net)
        {
            var NetWay = new SPNetWay();

            if (CheckStandartNetCondition(Net))
            {
                var Layers     = Net.GetLayers();
                var Settings   = Net.GetSettings();
                var LayerCount = Layers.Count;
                NetWay.layers = new List <SPNetWayLayer>();
                for (int i = 0; i < LayerCount; i++)
                {
                    var tmp = new SPNetWayLayer();
                    tmp.type   = Layers[i].GetLayerType();
                    tmp.blocks = new List <SPNetWayBlock>();
                    if (tmp.type != LayerType.SLayer)
                    {
                        var tmp_block = new SPNetWayBlock();
                        tmp_block.active_inputs  = new List <bool>();
                        tmp_block.active_outputs = new List <bool>();
                        tmp_block.active_inputs.AddRange(Enumerable.Repeat(false, Settings.WordLength));
                        tmp_block.active_outputs.AddRange(Enumerable.Repeat(false, Settings.WordLength));
                        tmp.blocks.Add(tmp_block);
                    }
                    else
                    {
                        foreach (var j in Enumerable.Range(0, Settings.SBoxCount))
                        {
                            var tmp_sblock = new SPNetWayBlock();
                            tmp_sblock.active_inputs  = new List <bool>();
                            tmp_sblock.active_outputs = new List <bool>();
                            tmp_sblock.active_inputs.AddRange(Enumerable.Repeat(false, Settings.SBoxSize));
                            tmp_sblock.active_outputs.AddRange(Enumerable.Repeat(false, Settings.SBoxSize));
                            tmp.blocks.Add(tmp_sblock);
                        }
                    }
                    NetWay.layers.Add(tmp);
                }
                return(NetWay);
            }
            else
            {
                throw new Exception("Azaza. Wrong net.");
            }
        }
Exemple #5
0
 public static void CopyOutToIn(SPNetWay Way, int SrcLIndex, int DestLIndex)
 {
     if (SrcLIndex < Way.layers.Count && DestLIndex < Way.layers.Count)
     {
         #region From S-layer to P-layer
         if (Way.layers[SrcLIndex].type == LayerType.SLayer && Way.layers[DestLIndex].type == LayerType.PLayer)
         {
             Way.layers[DestLIndex].blocks[0].active_inputs.Clear();
             for (int i = 0; i < Way.layers[SrcLIndex].blocks.Count; i++)
             {
                 for (int j = 0; j < Way.layers[SrcLIndex].blocks[i].active_outputs.Count; j++)
                 {
                     Way.layers[DestLIndex].blocks[0].active_inputs.Add(Way.layers[SrcLIndex].blocks[i].active_outputs[j]);
                 }
             }
         }
         #endregion
         #region From P-Layer to K-Layer
         if (Way.layers[SrcLIndex].type == LayerType.PLayer && Way.layers[DestLIndex].type == LayerType.KLayer)
         {
             var block = Way.layers[DestLIndex].blocks[0];
             block.active_inputs = Way.layers[SrcLIndex].blocks[0].active_outputs;
             Way.layers[DestLIndex].blocks[0] = block;
         }
         #endregion
         #region From K-Layer to S-Layer
         if (Way.layers[SrcLIndex].type == LayerType.KLayer && Way.layers[DestLIndex].type == LayerType.SLayer)
         {
             var srcBIndex = 0;
             for (int i = 0; i < Way.layers[DestLIndex].blocks.Count; i++)
             {
                 for (int j = 0; (j < Way.layers[DestLIndex].blocks[i].active_inputs.Count) && (srcBIndex < Way.layers[SrcLIndex].blocks[0].active_outputs.Count); j++, srcBIndex++)
                 {
                     Way.layers[DestLIndex].blocks[i].active_inputs[j] = Way.layers[SrcLIndex].blocks[0].active_outputs[srcBIndex];
                 }
             }
         }
         #endregion
     }
     else
     {
         Logger.UltraLogger.Instance.AddToLog("WayConverter: CopyOutToIn Func. I cant copy from and to this layer types.", Logger.MsgType.Error);
     }
 }
Exemple #6
0
        /// <summary>
        /// Deep Clone
        /// </summary>
        /// <param name="Way"></param>
        /// <param name="empty">Copy just struct without values</param>
        /// <returns></returns>
        public static SPNetWay CloneWay(SPNetWay Way, bool empty = false)
        {
            SPNetWay NewWay = new SPNetWay();

            if (Way.layers != null)
            {
                NewWay.layers = new List <SPNetWayLayer>(Way.layers.Count);
                for (int i = 0; i < Way.layers.Count; i++)
                {
                    var tmp_layer = new SPNetWayLayer();
                    tmp_layer.type = Way.layers[i].type;
                    if (Way.layers[i].blocks != null)
                    {
                        tmp_layer.blocks = new List <SPNetWayBlock>(Way.layers[i].blocks.Count);
                        for (int j = 0; j < Way.layers[i].blocks.Count; j++)
                        {
                            var tmp_block = new SPNetWayBlock();
                            if (Way.layers[i].blocks[j].active_inputs != null & Way.layers[i].blocks[j].active_outputs != null)
                            {
                                tmp_block.active_inputs  = new List <bool>(Way.layers[i].blocks[j].active_inputs.Count);
                                tmp_block.active_outputs = new List <bool>(Way.layers[i].blocks[j].active_outputs.Count);
                                tmp_block.active_inputs.AddRange(Enumerable.Repeat(false, Way.layers[i].blocks[j].active_inputs.Count));
                                tmp_block.active_outputs.AddRange(Enumerable.Repeat(false, Way.layers[i].blocks[j].active_outputs.Count));
                                if (!empty & (Way.layers[i].blocks[j].active_inputs.Count == Way.layers[i].blocks[j].active_outputs.Count))
                                {
                                    for (int k = 0; k < Way.layers[i].blocks[j].active_inputs.Count; k++)
                                    {
                                        tmp_block.active_inputs[k]  = Way.layers[i].blocks[j].active_inputs[k];
                                        tmp_block.active_outputs[k] = Way.layers[i].blocks[j].active_outputs[k];
                                    }
                                }
                            }
                            tmp_layer.blocks.Add(tmp_block);
                        }
                    }
                    NewWay.layers.Add(tmp_layer);
                }
            }
            return(NewWay);
        }
Exemple #7
0
 public Solution(Prevalence p, SPNetWay w)
 {
     P   = p;
     Way = w;
 }