예제 #1
0
        /// <summary>
        /// HOWTO: Enter the algorithm you'd like to implement in this method.
        /// </summary>
        public void Execute()
        {
            Double[,] BigraphStat;
            string BsPath;
            int    matrixSize;

            ProgressChanged(0, 1);

            // Check settings
            if (settings.HeapSize < 1)
            {
                System.Windows.MessageBox.Show("Heap size has to be a positiv integer!\nHeap size is set to 5000");
                settings.HeapSize = 5000;
            }


            // BigraphStatistic.CreateBS(@"c:\Documents and Settings\PT7130\My Documents\Visual Studio 2010\Projects\Cryptool2\trunk\CrypPlugins\PlayfairAnalysis\Data\", 6);

            if (settings.UseCustomStatistic == 1)       // Use Bigraph Statistic that is generated by PlayfairAnalysisStatistic plugin
            {
                int alphabetLength;
                int offset = 0;
                using (CStreamReader reader = CustomLogStat.CreateReader())
                {
                    alphabetLength = (int)reader.ReadByte();
                    matrixSize     = (int)(Math.Sqrt(alphabetLength));

                    BigraphStat = new Double[(int)Math.Pow(matrixSize, 2), (int)Math.Pow(matrixSize, 2)];
                    byte[] statisticBuffer = new byte[8 * BigraphStat.Length];

                    alphabet = "";
                    for (int i = 0; i < alphabetLength; i++)
                    {
                        alphabet += (char)reader.ReadByte();
                    }


                    reader.ReadFully(statisticBuffer, offset, 8 * BigraphStat.Length);


                    for (int i = 0; i < (int)Math.Pow(matrixSize, 2); i++)
                    {
                        for (int j = 0; j < (int)Math.Pow(matrixSize, 2); j++)
                        {
                            BigraphStat[i, j] = BitConverter.ToDouble(statisticBuffer, offset);
                            offset           += 8;
                        }
                    }
                }

                GuiLogMessage("MatrixSize: " + Convert.ToString(matrixSize), NotificationLevel.Info);
                GuiLogMessage("Custom Bigraph Stat successfully set", NotificationLevel.Info);
            }

            else          // Read Bigraph Statistic from xml file
            {
                switch (settings.MatrixSize)
                {
                case 0:
                    if (settings.Language == 0)
                    {
                        BsPath = @"c:\Documents and Settings\PT7130\My Documents\Visual Studio 2010\Projects\Cryptool2\trunk\CrypPlugins\PlayfairAnalysis\Data\BSLog10sde.xml";
                    }
                    else
                    {
                        BsPath = @"c:\Documents and Settings\PT7130\My Documents\Visual Studio 2010\Projects\Cryptool2\trunk\CrypPlugins\PlayfairAnalysis\Data\BSLog10seng.xml";
                    }
                    matrixSize = 5;
                    alphabet   = "ABCDEFGHIKLMNOPQRSTUVWXYZ";

                    break;

                case 1:
                    if (settings.Language == 0)
                    {
                        BsPath = @"c:\Documents and Settings\PT7130\My Documents\Visual Studio 2010\Projects\Cryptool2\trunk\CrypPlugins\PlayfairAnalysis\Data\BSLog10lde.xml";
                    }
                    else
                    {
                        BsPath = @"c:\Documents and Settings\PT7130\My Documents\Visual Studio 2010\Projects\Cryptool2\trunk\CrypPlugins\PlayfairAnalysis\Data\BSLog10leng.xml";
                    }
                    matrixSize = 6;
                    alphabet   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                    break;

                default:
                    BsPath     = @"c:\Documents and Settings\PT7130\My Documents\Visual Studio 2010\Projects\Cryptool2\trunk\CrypPlugins\PlayfairAnalysis\Data\BSLog10sde.xml";
                    matrixSize = 5;
                    alphabet   = "ABCDEFGHIKLMNOPQRSTUVWXYZ";
                    break;
                }

                BigraphStat = new Double[(int)Math.Pow(matrixSize, 2), (int)Math.Pow(matrixSize, 2)];

                System.Xml.Serialization.XmlSerializer ReadBS = new System.Xml.Serialization.XmlSerializer(typeof(Double[][]));
                System.Xml.XmlReader XmlReader        = System.Xml.XmlReader.Create(BsPath);
                Double[][]           BigraphStatDummy = (Double[][])ReadBS.Deserialize(XmlReader);
                XmlReader.Close();

                for (int i = 0; i < Math.Pow(matrixSize, 2); i++)
                {
                    for (int j = 0; j < Math.Pow(matrixSize, 2); j++)
                    {
                        BigraphStat[i, j] = BigraphStatDummy[i][j];
                    }
                }

                GuiLogMessage("MatrixSize: " + Convert.ToString(matrixSize), NotificationLevel.Info);
                GuiLogMessage("Bigraph statistics loaded: " + BsPath, NotificationLevel.Info);
            }

            GuiLogMessage("Starting Analysis", NotificationLevel.Info);

            KeySearcher keySearcher = new KeySearcher(matrixSize, settings.HeapSize, BigraphStat, alphabet, InputString);

            keySearcher.LogMessageByKeySearcher      += new KeySearcher.LogMessageByKeySearcherEventHandler(OnLogMessageByKeySearcher);
            keySearcher.ProgressChangedByKeySearcher += new KeySearcher.ProgressChangedByKeySearcherEventHandler(OnProgressChangedByKeySearcher);

            playFairAttackThread = new Thread(keySearcher.Attack);
            playFairAttackThread.IsBackground = true;

            playFairAttackThread.Start();
            playFairAttackThread.Join();

            if (!executionStopped)
            {
                OutputString = keySearcher.PlainText;
                OnPropertyChanged("OutputString");
                OnPropertyChanged("OutputData");
                GuiLogMessage("Analysis completed", NotificationLevel.Info);
                ProgressChanged(1, 1);
            }
            else
            {
                GuiLogMessage("Analysis aborted", NotificationLevel.Info);
                ProgressChanged(0, 1);
            }
        }
예제 #2
0
 public BigraphStatistic(int matrixSize)
 {
     keySearcher     = new KeySearcher(matrixSize);
     this.matrixSize = matrixSize;
 }