Ejemplo n.º 1
0
        private FipsResult StartTestWithTxt()
        {
            if (wynik.Text.Length < 20000)
            {
                //Jak ciąg będzie mniejszy niż <20000 to zwraca null, potem a potem można sprawdzić czy result jest nullem i coś zadziałać :)
                return(null);
            }

            var        input      = (wynik.Text).Substring(0, 20000);
            FipsResult fipsResult = new FipsResult()
            {
                SingleBitTestResult  = fips.SingleBitTest(input),
                SeriesTestResult     = fips.SeriesTest(input),
                LongSeriesTestResult = fips.LongSeriesTests(input),
                PokerTestResult      = fips.PokerTest(input)
            };

            return(fipsResult);
        }
        private void GenerateBtn_Click(object sender, RoutedEventArgs e)
        {
            string r1 = r1State.Content as string;
            string r2 = r2State.Content as string;
            string r3 = r3State.Content as string;

            Lfsr[] lfsrs = new Lfsr[3];

            lfsrs[0] = new Lfsr(r1);
            lfsrs[1] = new Lfsr(r2);
            lfsrs[2] = new Lfsr(r3);


            //setting custom feedback function
            ChangeLfsrFeedbackFunctions(lfsrs);

            for (int i = 0; i < lfsrs.Length; i++)
            {
                generator.ChangeRegister(lfsrs[i], i);
            }

            var format = outputFormatComboBox.SelectedIndex;

            int seriesLength = 0;

            if (outputLength.Text != "")
            {
                seriesLength = int.Parse(outputLength.Text);
            }

            ClearOutput();

            Task.Run(() =>
            {
                SetLoadingCircle(true);
                disableButtons();
                ResetFipsIcons();
                byte[] generatedBytes = null;
                switch (format)
                {
                case 0:
                    {
                        lastGeneratedFormat = format;
                        lastGeneratedString = new string(generator.GenerateBitsAsChars(seriesLength));
                        SetOutputText(lastGeneratedString);
                        SetLoadingCircle(false);
                        break;
                    }

                case 1:
                    {
                        generatedBytes      = generator.GenerateBytes(seriesLength);
                        lastGeneratedFormat = format;
                        lastGeneratedString = Convert.ToBase64String(generatedBytes);
                        SetOutputText(lastGeneratedString);
                        SetLoadingCircle(false);
                        break;
                    }

                default:
                    break;
                }
                UpdateRegisterState(generator);
                enableButtons();

                if (seriesLength >= 20000)
                {
                    SingleBitTestResult singleBitResult   = null;
                    SeriesTestResult seriesResult         = null;
                    LongSeriesTestResult longSeriesResult = null;
                    PokerTestResult pokerResult           = null;

                    if (format == 0)
                    {
                        FipsTests fipsTests = new FipsTests();
                        var testInput       = lastGeneratedString.Substring(0, 20000);

                        singleBitResult  = fipsTests.SingleBitTest(testInput);
                        seriesResult     = fipsTests.SeriesTest(testInput);
                        longSeriesResult = fipsTests.LongSeriesTests(testInput);
                        pokerResult      = fipsTests.PokerTest(testInput);
                    }
                    else if (format == 1)
                    {
                        FipsTests fipsTests = new FipsTests();
                        byte[] testArray    = new byte[2500];
                        Array.Copy(generatedBytes, testArray, 2500);
                        if (generatedBytes != null)
                        {
                            singleBitResult  = fipsTests.SingleBitTest(testArray);
                            seriesResult     = fipsTests.SeriesTest(testArray);
                            longSeriesResult = fipsTests.LongSeriesTests(testArray);
                            pokerResult      = fipsTests.PokerTest(testArray);
                        }
                    }

                    if (singleBitResult.TestPassed)
                    {
                        singleBitSuccess();
                    }
                    else
                    {
                        singleBitFail();
                    }
                    if (seriesResult.TestPassed)
                    {
                        seriesSuccess();
                    }
                    else
                    {
                        seriesFail();
                    }
                    if (longSeriesResult.TestPassed)
                    {
                        longSeriesSuccess();
                    }
                    else
                    {
                        longSeriesFail();
                    }
                    if (pokerResult.TestPassed)
                    {
                        pokerSuccess();
                    }
                    else
                    {
                        pokerFail();
                    }
                }
            });
        }