示例#1
0
        private static void SortStates()
        {
            for (int i = Ciphers.Count - 1; i >= 0; i--)
            {
                if (DKAEndNodes.Contains(Ciphers[i]))
                {
                    Ciphers.Remove(Ciphers[i]);
                    Paths.Remove(Paths[i]);
                }
            }

            string        tempCipher;
            List <string> tempPath;

            for (int i = 0; i < Ciphers.Count; i++)
            {
                for (int j = i + 1; j < Ciphers.Count; j++)
                {
                    if (Convert.ToInt32(Ciphers[i].Split(',')[0]) > Convert.ToInt32(Ciphers[j].Split(',')[0]))
                    {
                        tempCipher = Ciphers[i];
                        Ciphers[i] = Ciphers[j];
                        Ciphers[j] = tempCipher;

                        tempPath = Paths[i];
                        Paths[i] = Paths[j];
                        Paths[j] = tempPath;
                    }
                }
            }

            for (int i = 0; i < DKAEndNodes.Count; i++)
            {
                for (int j = i + 1; j < DKAEndNodes.Count; j++)
                {
                    if (Convert.ToInt32(DKAEndNodes[i]) > Convert.ToInt32(DKAEndNodes[j]))
                    {
                        string tempNode = DKAEndNodes[i];
                        DKAEndNodes[i] = DKAEndNodes[j];
                        DKAEndNodes[j] = tempNode;
                    }
                }
            }

            DKAEndNodes.Add(DKAEndNodes[0]);
            DKAEndNodes.RemoveAt(0);

            Ciphers.AddRange(DKAEndNodes);
            for (int i = 0; i < DKAEndNodes.Count; i++)
            {
                Paths.Add(new List <string>());

                for (int k = 0; k < Labels.Length; k++)
                {
                    Paths[Paths.Count - 1].Add("$");
                }
            }
        }
示例#2
0
        private static void SetStartedSuffixes()
        {
            string[] baseSuffixes = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "M", "N", "O", "P", "Q", "R", "S", "T" };

            int endFlagIndex = 1;

            Suffixes = new List <string>();
            for (int j = 0; j < Ciphers.Count; j++)
            {
                if (DKAEndNodes.Contains(Ciphers[j]))
                {
                    Suffixes.Add(baseSuffixes[endFlagIndex++]);
                }
                else
                {
                    Suffixes.Add(baseSuffixes[0]);
                }
            }
        }
示例#3
0
        private static void DeleteRepeatedStates()
        {
            for (int i = 0; i < Paths.Count; i++)
            {
                for (int j = i + 1; j < Paths.Count; j++)
                {
                    bool areEquals = true;

                    for (int k = 0; k < Labels.Length; k++)
                    {
                        if (Paths[i][k] != Paths[j][k])
                        {
                            areEquals = false;
                            break;
                        }
                    }

                    if (areEquals && Paths[i][0] != "$" && !DKAEndNodes.Contains(Ciphers[j]) && !DKAEndNodes.Contains(Ciphers[i]))
                    {
                        Console.WriteLine("Найдены эквивалентные состояния: {0} и {1}\n", Ciphers[i], Ciphers[j]);

                        Paths[i].Clear();
                        Paths[i] = null;

                        for (int k = 0; k < Paths.Count; k++)
                        {
                            for (int f = 0; f < Labels.Length; f++)
                            {
                                if (Paths[k] == null)
                                {
                                    continue;
                                }

                                if (Paths[k][f].Contains(Ciphers[i]))
                                {
                                    Paths[k][f] = Paths[k][f].Replace(Ciphers[i], Ciphers[j]);
                                }
                            }
                        }

                        for (int k = 0; k < Ciphers.Count; k++)
                        {
                            if (k != i && Ciphers[k].Contains(Ciphers[i]))
                            {
                                Ciphers[k] = Ciphers[k].Replace(Ciphers[i], Ciphers[j]);
                            }
                        }

                        break;
                    }
                }
            }

            for (int i = 0; i < Paths.Count; i++)
            {
                if (Paths[i] == null)
                {
                    Paths.Remove(Paths[i]);
                    Ciphers.Remove(Ciphers[i]);
                }
            }
        }