Пример #1
0
        protected override void DoExecute()
        {
            FireOnStart();

            PrimesBigInteger from = m_From;

            while (from.CompareTo(m_To) <= 0)
            {
                if (from.IsPrime(20))
                {
                    FireOnMessage(this, from, from.Subtract(PrimesBigInteger.One).ToString("D"));
                }
                else
                {
                    PrimesBigInteger d       = PrimesBigInteger.One;
                    PrimesBigInteger counter = PrimesBigInteger.Zero;

                    while (d.CompareTo(from) < 0)
                    {
                        if (PrimesBigInteger.GCD(d, from).Equals(PrimesBigInteger.One))
                        {
                            counter = counter.Add(PrimesBigInteger.One);
                            FireOnMessage(this, from, counter.ToString("D"));
                        }
                        d = d.Add(PrimesBigInteger.One);
                    }

                    FireOnMessage(this, from, counter.ToString("D"));
                }

                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Пример #2
0
        private void Factorize(PrimesBigInteger value)
        {
            ClearInfoPanel();
            string inputvalue = m_Integer.ToString();

            if (lblInput.ToolTip == null)
            {
                lblInput.ToolTip = new ToolTip();
            }
            (lblInput.ToolTip as ToolTip).Content = StringFormat.FormatString(inputvalue, 80);

            if (inputvalue.Length > 7)
            {
                inputvalue = inputvalue.Substring(0, 6) + "...";
            }
            System.Windows.Documents.Underline ul = new Underline();

            if (CurrentFactorizer == _bruteforce)
            {
                BF.lblInput = inputvalue;
            }
            else
            {
                QS.lblInput = inputvalue;
            }

            UpdateMessages();

            CurrentFactorizer.Execute(value);
        }
Пример #3
0
        protected override void DoExecute()
        {
            FireOnStart();
            PrimesBigInteger from = m_From;

            while (from.CompareTo(m_To) <= 0)
            {
                PrimesBigInteger result = PrimesBigInteger.Zero;
                PrimesBigInteger k      = PrimesBigInteger.One;
                while (k.CompareTo(from) <= 0)
                {
                    if (from.Mod(k).Equals(PrimesBigInteger.Zero))
                    {
                        PrimesBigInteger phik = EulerPhi(k);
                        result = result.Add(phik);
                        FireOnMessage(this, from, result.ToString());
                    }
                    k = k.Add(PrimesBigInteger.One);
                }
                FireOnMessage(this, from, result.ToString());
                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Пример #4
0
        private void ExecuteStair()
        {
            FunctionExecute fe = m_FunctionExecute;
            double x1 = m_XStart;
            PrimesBigInteger incX = PrimesBigInteger.One;
            PrimesBigInteger inci = PrimesBigInteger.One;
            PrimesBigInteger div = (fe.Range.RangeAmount.CompareTo(PrimesBigInteger.ValueOf(10000)) > 0) ? PrimesBigInteger.Ten : PrimesBigInteger.OneHundred;
            if (fe.Range.RangeAmount.CompareTo(PrimesBigInteger.ValueOf(1000)) > 0 && fe.Function.CanEstimate)
            {
                inci = fe.Range.RangeAmount.Divide(div);
                incX = inci;
            }

            PrimesBigInteger i = m_From;
            while (i.CompareTo(fe.Range.To) <= 0 && !HasTerminateRequest())
            {
                Boolean awokenByTerminate = SuspendIfNeeded();

                if (awokenByTerminate)
                {
                    m_From = i;
                    return;
                }

                double param = i.DoubleValue;

                double formerY = fe.Function.FormerValue;
                double y = fe.Function.Execute(param);

                bool drawstair = !formerY.Equals(y) || formerY.Equals(double.NaN);
                if (formerY.Equals(double.NaN)) formerY = y;
                double x2 = x1 + double.Parse(incX.ToString());
                if (fe.Function.DrawTo.Equals(double.PositiveInfinity) || (x2 <= fe.Function.DrawTo && x2 <= fe.Range.To.DoubleValue))
                {
                    if (drawstair)
                    {
                        x2 -= double.Parse(incX.ToString());
                    }
                    if (!DrawLine(x1, x2, formerY, y, fe.Color, fe.Function)) break;
                    if (drawstair)
                    {
                        x2 += double.Parse(incX.ToString());
                        if (!DrawLine(x1, x2, y, y, fe.Color, fe.Function)) break;
                    }
                }

                x1 = x2;
                i = i.Add(inci);
            }
        }
Пример #5
0
        private void ResetMessages(PrimesBigInteger value)
        {
            switch (KindOfFactorization)
            {
            case KOF.BruteForce:
                BF.FreeText = value.ToString();
                break;

            case KOF.QS:
                QS.FreeText = value.ToString();
                break;
            }

            ResetMessages();
        }
Пример #6
0
        //  private void FastTrialDivision()
        //  {
        //      m_Height = 0;
        //  PrimesBigInteger m_factor = PrimesBigInteger.Two;
        //      int mod30 = m_factor.Mod(PrimesBigInteger.ValueOf(30)).IntValue;
        //      PrimesBigInteger value = new PrimesBigInteger(this.m_Root.Value);
        //      PrimesBigInteger max = value.SquareRoot();
        //      GmpFactorTreeNode node = this.m_Root;
        //bool run = true;
        //if (value.IsProbablePrime(10))
        //  run = false;

        //      while (run)
        //      {
        //          while (m_factor.CompareTo(max) <= 0)
        //          {
        //              if (!(mod30 == 1 ||
        //               mod30 == 7 ||
        //               mod30 == 11 ||
        //               mod30 == 13 ||
        //               mod30 == 17 ||
        //               mod30 == 19 ||
        //               mod30 == 23 ||
        //               mod30 == 29 ||
        //               m_factor.CompareTo(PrimesBigInteger.Two) == 0 ||
        //               m_factor.CompareTo(PrimesBigInteger.ValueOf(3)) == 0 ||
        //               m_factor.CompareTo(PrimesBigInteger.ValueOf(5)) == 0))
        //              {
        //                  m_factor = m_factor.Add(PrimesBigInteger.One);
        //                  mod30++;
        //                  (mod30) %= 30;
        //                  continue;
        //              }
        //              if (value.Mod(m_factor).CompareTo(PrimesBigInteger.Zero)==0)
        //              {
        //                  value = value.Divide(m_factor);
        //      m_Remainder = value;

        //                  max = value.SquareRoot();
        //                  GmpFactorTreeNode primeNodeTmp = new GmpFactorTreeNode(m_factor);
        //      primeNodeTmp.IsPrime = m_factor.IsPrime(10);
        //      m_Height++;
        //      AddFactor(m_factor);
        //      node.AddChild(primeNodeTmp);
        //                  node = node.AddChild(new GmpFactorTreeNode(value));
        //                  continue;
        //              }
        //              m_factor = m_factor.Add(PrimesBigInteger.One);
        //              mod30++;
        //              (mod30) %= 30;
        //              run = false;
        //          }
        //          run = false;
        //      }
        //m_Remainder = null;
        //      node.IsPrime = true;
        //      AddFactor(value);
        //  }

        private void AddFactor(PrimesBigInteger value)
        {
            if (m_Factors.ContainsKey(value.ToString()))
            {
                m_Factors[value.ToString()] = m_Factors[value.ToString()].Add(PrimesBigInteger.One);
            }
            else
            {
                m_Factors.Add(value.ToString(), PrimesBigInteger.One);
            }
            if (OnFactorFound != null)
            {
                OnFactorFound();
            }
        }
Пример #7
0
        private void DoFactorize(PrimesBigInteger value)
        {
            /*
             *        if (N.compareTo(ONE) == 0) return;
             * if (N.isProbablePrime(20)) { System.out.println(N); return; }
             * BigInteger divisor = rho(N);
             * factor(divisor);
             * factor(N.divide(divisor));
             */
            if (value.Equals(PrimesBigInteger.One))
            {
                return;
            }
            if (value.IsProbablePrime(10))
            {
                if (!m_Factors.ContainsKey(value))
                {
                    m_Factors.Add(value, PrimesBigInteger.Zero);
                }
                PrimesBigInteger tmp = m_Factors[value];
                m_Factors[value] = tmp.Add(PrimesBigInteger.One);

                if (FoundFactor != null)
                {
                    FoundFactor(m_Factors.GetEnumerator());
                }
                log.Info(value.ToString());
                return;
            }
            else
            {
                if (!m_FactorsTmp.ContainsKey(value))
                {
                    m_FactorsTmp.Add(value, 0);
                }
                m_FactorsTmp[value]++;
                if (m_FactorsTmp[value] > 3)
                {
                    log.Info(value.ToString() + " Zu oft");
                    m_A = PrimesBigInteger.RandomM(value).Add(PrimesBigInteger.Two);
                    m_FactorsTmp.Remove(value);
                }
            }
            PrimesBigInteger div = CalculateFactor(value);

            DoFactorize(div);
            DoFactorize(value.Divide(div));
        }
Пример #8
0
        public string OnFoundFactor_FactorTree(GmpFactorTree ft)
        {
            StringBuilder sbFactors = new StringBuilder();

            if (ft != null)
            {
                sbFactors.Append(" = ");

                foreach (string factor in ft.Factors)
                {
                    sbFactors.Append(factor.ToString());
                    PrimesBigInteger factorcount = ft.GetFactorCount(factor);
                    if (factorcount > 1)
                    {
                        sbFactors.AppendFormat("^{0}", factorcount.ToString());
                    }
                    sbFactors.Append(" * ");
                }

                if (ft.Remainder != null)
                {
                    sbFactors.Append(ft.Remainder.ToString());
                }
                else
                {
                    sbFactors = sbFactors.Remove(sbFactors.Length - 2, 2);
                }
            }

            return(sbFactors.ToString());
        }
Пример #9
0
        protected override void DoExecute()
        {
            FireOnStart();

            PrimesBigInteger from = m_From;

            while (from.CompareTo(m_To) <= 0)
            {
                StringBuilder    sbMessage = new StringBuilder("[");
                PrimesBigInteger d         = PrimesBigInteger.One;
                while (d.CompareTo(from) < 0)
                {
                    if (PrimesBigInteger.GCD(d, from).Equals(PrimesBigInteger.One))
                    {
                        if (sbMessage.Length > 1)
                        {
                            sbMessage.Append(", ");
                        }
                        sbMessage.Append(d.ToString());
                        FireOnMessage(this, from, sbMessage.ToString());
                    }
                    d = d.Add(PrimesBigInteger.One);
                }
                sbMessage.Append("]");
                FireOnMessage(this, from, sbMessage.ToString());

                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Пример #10
0
 private void SetFromTo()
 {
     ControlHandler.SetPropertyValue(iscFrom, "FreeText", m_Start.ToString());
     ControlHandler.SetPropertyValue(iscTo, "FreeText", m_End.ToString());
     ControlHandler.SetPropertyValue(lblInfoCountPrimesInterval, "Text", string.Format(Distribution.numberline_numberofprimeinterval, m_Start, m_End));
     SetEdgeButtonColor();
 }
Пример #11
0
        protected override void DoExecute()
        {
            FireOnStart();

            try
            {
                PrimesBigInteger modulus = m_SecondParameter;

                PrimesBigInteger from = m_From;

                while (from.CompareTo(m_To) <= 0)
                {
                    string msg;
                    try
                    {
                        PrimesBigInteger result = from.ModInverse(modulus);
                        msg = result.ToString("D");
                    }
                    catch (Exception ex)
                    {
                        msg = "-";
                    }
                    FireOnMessage(this, from, msg);
                    from = from.Add(PrimesBigInteger.One);
                }
            }
            catch (Exception ex)
            {
            }

            FireOnStop();
        }
Пример #12
0
        private void DrawNumberButton(PrimesBigInteger value, double x, double y)
        {
            Ellipse nb = ControlHandler.CreateObject(typeof(Ellipse)) as Ellipse;

            //NumberButton nb = ControlHandler.CreateObject(typeof(NumberButton)) as NumberButton;
            //ControlHandler.SetPropertyValue(nb, "NumberButtonStyle", NumberButtonStyle.Ellipse.ToString());
            //ControlHandler.SetPropertyValue(nb, "BINumber", value);
            ControlHandler.SetPropertyValue(nb, "Width", 6);
            ControlHandler.SetPropertyValue(nb, "Height", 6);
            ToolTip tt = ControlHandler.CreateObject(typeof(ToolTip)) as ToolTip;

            ControlHandler.SetPropertyValue(tt, "Content", value.ToString());
            ControlHandler.SetPropertyValue(nb, "ToolTip", tt);

            //if (value.IsPrime(10))
            //  ControlHandler.SetPropertyValue(nb, "Background", Brushes.Blue);
            //else
            //  ControlHandler.SetPropertyValue(nb, "Background", Brushes.Gray);
            if (value.IsPrime(10))
            {
                ControlHandler.SetPropertyValue(nb, "Fill", Brushes.Blue);
            }
            else
            {
                ControlHandler.SetPropertyValue(nb, "Fill", Brushes.Gray);
            }

            ControlHandler.ExecuteMethod(PaintArea, "SetTop", new object[] { nb, y - 3 });
            ControlHandler.ExecuteMethod(PaintArea, "SetLeft", new object[] { nb, x - 3 });
            ControlHandler.AddChild(nb, PaintArea);
        }
Пример #13
0
        protected override void DoExecute()
        {
            FireOnStart();

            for (PrimesBigInteger from = m_From; from <= m_To; from = from + 1)
            {
                PrimesBigInteger counter = 0;

                for (PrimesBigInteger d = 1; d * 2 <= from; d = d + 1)
                {
                    if (from.Mod(d).Equals(PrimesBigInteger.Zero))
                    {
                        counter = counter + 1;
                        FireOnMessage(this, from, counter.ToString());
                    }
                }
                counter = counter + 1;
                FireOnMessage(this, from, counter.ToString());
            }

            FireOnStop();
        }
Пример #14
0
        protected override void DoExecute()
        {
            FireOnStart();

            for (PrimesBigInteger from = m_From; from.CompareTo(m_To) <= 0; from = from + 1)
            {
                PrimesBigInteger sum = 0;

                for (PrimesBigInteger d = 1; d * 2 <= from; d = d + 1)
                {
                    if (from.Mod(d).Equals(PrimesBigInteger.Zero))
                    {
                        sum = sum + d;
                        FireOnMessage(this, from, sum.ToString());
                    }
                }

                sum = sum + from;
                FireOnMessage(this, from, sum.ToString());
            }

            FireOnStop();
        }
Пример #15
0
        private bool ExecuteLog(PrimesBigInteger a)
        {
            PrimesBigInteger result = a.ModPow(m_Value.Subtract(PrimesBigInteger.One), m_Value);

            log.Info(
                string.Format(
                    "Berechne {0}^{1} mod {2} = {3}",
                    new object[] { a.ToString(), m_Value.Subtract(PrimesBigInteger.One), m_Value.ToString(), result.ToString() }));
            ControlHandler.SetPropertyValue(lblA, "Content", a.ToString());
            ControlHandler.SetPropertyValue(lblExp, "Text", m_Value.ToString() + "-1");
            ControlHandler.SetPropertyValue(lblP, "Content", m_Value.ToString());
            ControlHandler.SetPropertyValue(lblCalc, "Text", result.ToString());

            if (result.Equals(PrimesBigInteger.One))
            {
                log.Info(string.Format("{0} hat den Fermattest bestanden und ist mir einer Wahrscheinlichkeit von 50% eine Primzahl", m_Value.ToString()));
            }
            else
            {
                log.Info(string.Format("{0} hat den Fermattest nicht bestanden und ist damit definitiv keine Primzahl. {1} ist Belastungszeuge gegen {2}", new object[] { m_Value.ToString(), a.ToString(), m_Value.ToString() }));
            }

            return(result.Equals(PrimesBigInteger.One));
        }
Пример #16
0
        private void miHeader_Click(object sender, RoutedEventArgs e)
        {
            int rndNumber          = rndGenerate.Next(950);
            PrimesBigInteger prime = PrimesBigInteger.ValueOf(rndNumber).NextProbablePrime();

            if (!string.IsNullOrEmpty(tbInput.Text))
            {
                tbInput.Text += ", ";
            }
            else
            {
                HideInfo();
            }
            tbInput.Text += prime.ToString();
        }
Пример #17
0
        private void InitInput()
        {
            ircGoldbach.Execute += new Primes.WpfControls.Components.ExecuteDelegate(ircGoldbach_Execute);
            ircGoldbach.Cancel  += new VoidDelegate(ircGoldbach_Cancel);

            ircGoldbach.SetText(InputRangeControl.FreeFrom, m_From.ToString());
            ircGoldbach.SetText(InputRangeControl.FreeTo, m_To.ToString());

            InputValidator <PrimesBigInteger> ivFrom = new InputValidator <PrimesBigInteger>();

            ivFrom.Validator = new BigIntegerMinValueMaxValueValidator(null, 2, 100000);
            ircGoldbach.AddInputValidator(InputRangeControl.FreeFrom, ivFrom);
            InputValidator <PrimesBigInteger> ivTo = new InputValidator <PrimesBigInteger>();

            ivTo.Validator = new BigIntegerMinValueMaxValueValidator(null, 2, 100000);
            ircGoldbach.AddInputValidator(InputRangeControl.FreeTo, ivTo);
        }
Пример #18
0
 void f1_Message(INTFunction function, PrimesBigInteger value, string message)
 {
     lock (locksetdata)
     {
         if (m_ColumnsDict.ContainsKey(function))
         {
             DataRow[] rows = m_DataTable.Select("n = '" + value.ToString() + "'");
             if (rows != null && rows.Length == 1)
             {
                 DataColumn dc  = m_ColumnsDict[function];
                 int        col = m_DataTable.Columns.IndexOf(dc);
                 int        row = m_DataTable.Rows.IndexOf(rows[0]);
                 SetData(col, row, message);
             }
         }
     }
 }
Пример #19
0
        public PrimitivRootControl()
        {
            InitializeComponent();
            this.OnStart    += new VoidDelegate(PrimitivRootControl_OnStart);
            this.OnStop     += new VoidDelegate(PrimitivRootControl_OnStop);
            validator        = new BigIntegerMinValueMaxValueValidator(null, MIN, MAX);
            log.OverrideText = true;
            int mersenneexp = mersenneseed[new Random().Next(mersenneseed.Length - 1)];

            tbInput.Text  = PrimesBigInteger.Random(2).Add(PrimesBigInteger.Three).NextProbablePrime().ToString();
            tbInput.Text += ", 2^" + mersenneexp + "-1";
            PrimesBigInteger rangeval = PrimesBigInteger.Random(2).Add(PrimesBigInteger.Three);

            tbInput.Text += ", " + rangeval.ToString() + ":" + rangeval.Add(PrimesBigInteger.Ten).ToString();

            rndGenerate      = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
            m_JumpLockObject = new object();
        }
Пример #20
0
        private void setActualNumberText(PrimesBigInteger value)
        {
            string text = value.ToString("D");

            lblActualNumber.Text = text;
            //if (m_Start.Add(m_End).Divide(PrimesBigInteger.Two).CompareTo(value) > 0)
            //{
            //    textActualNumberleft.Visibility = Visibility.Collapsed;
            //    textActualNumberright.Visibility = Visibility.Visible;
            //    textActualNumberright.Text = text;
            //}
            //else
            //{
            //    textActualNumberright.Visibility = Visibility.Collapsed;
            //    textActualNumberleft.Visibility = Visibility.Visible;
            //    textActualNumberleft.Text = text;
            //}

            textActualNumber.Text = text;
        }
        void exec_FunctionResult(PrimesBigInteger result, PrimesBigInteger input)
        {
            int row = log.NewLine();

            if (m_ExpressionExecuter.Function != null && m_ExpressionExecuter.Function.GetType().GetInterface("IPolynom") != null)
            {
                log.Info(string.Format("f({0}) = {1}", new object[] { input, result }), 0, row);
                bool isPrime = result.IsPrime(10);
                lock (counterlockobject)
                {
                    m_PolynomGeneratedCount++;
                    m_PolynomGeneratedPrimes += (isPrime) ? 1 : 0;
                }
                log.Info((isPrime) ? Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.isPrime : Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.isNotPrime, 1, row);
            }
            else
            {
                log.Info(result.ToString(), 0, row);
            }
        }
Пример #22
0
        private void DoFactorize(object o)
        {
            if (o == null)
            {
                return;
            }

            Dictionary <PrimesBigInteger, long> factors = null;
            PrimesBigInteger value = null;

            if (o.GetType() == typeof(PrimesBigInteger))
            {
                ControlHandler.SetPropertyValue(lblCalcFactorizationInfo, "Text", Distribution.numberline_factorizationcalculating);
                value   = o as PrimesBigInteger;
                factors = value.Factorize();
            }
            else if (o.GetType() == typeof(Dictionary <PrimesBigInteger, long>))
            {
                factors = o as Dictionary <PrimesBigInteger, long>;
                value   = PrimesBigInteger.Refactor(factors);
            }

            if (factors != null)
            {
                String s = value.ToString();
                if (!value.IsPrime(20) && !value.Equals(PrimesBigInteger.One))
                {
                    s += " = " + String.Join(" * ", factors.Keys.Select(i => i + ((factors[i] > 1) ? "^" + factors[i] : "")).ToArray());
                }

                ControlHandler.SetPropertyValue(lblFactors, "Visibility", Visibility.Visible);
                ControlHandler.SetPropertyValue(lblFactors, "Text", s);
            }

            if (FactorizationDone != null)
            {
                FactorizationDone();
            }
        }
Пример #23
0
        public string OnFoundFactor_Enumerator(IEnumerator <KeyValuePair <PrimesBigInteger, PrimesBigInteger> > _enum)
        {
            StringBuilder sbFactors = new StringBuilder();

            sbFactors.Append(" = ");

            while (_enum.MoveNext())
            {
                KeyValuePair <PrimesBigInteger, PrimesBigInteger> current = _enum.Current;
                sbFactors.Append(current.Key.ToString());
                PrimesBigInteger factorcount = current.Value;
                if (factorcount > 1)
                {
                    sbFactors.AppendFormat("^{0}", factorcount.ToString());
                }
                sbFactors.Append(" * ");
            }

            sbFactors = sbFactors.Remove(sbFactors.Length - 2, 2);

            return(sbFactors.ToString());
        }
Пример #24
0
        protected override void DoExecute()
        {
            FireOnStart();

            try
            {
                PrimesBigInteger modulus = m_SecondParameter;

                PrimesBigInteger from = m_From;

                while (from.CompareTo(m_To) <= 0)
                {
                    PrimesBigInteger result = PrimesBigInteger.GCD(from, modulus);
                    FireOnMessage(this, from, result.ToString("D"));
                    from = from.Add(PrimesBigInteger.One);
                }
            }
            catch (Exception ex)
            {
            }

            FireOnStop();
        }
Пример #25
0
        public PrimesBigInteger Execute(PrimesBigInteger input)
        {
            int l = m_Length.IntValue;

            // try to find a random prime in the range
            for (int i = 0; i < 2; i++)
            {
                m_LastPrime = GetStartBigInteger();
                if (m_LastPrime.ToString().Length != l) continue;
                if (!m_GeneratedPrimes.Contains(m_LastPrime))
                {
                    m_GeneratedPrimes.Add(m_LastPrime);
                    return m_LastPrime;
                }
            }

            // if that fails, try to find a prime systematically from the start of the range
            StringBuilder r = new StringBuilder("1");
            for (int i = 1; i < l; i++) r.Append("0");
            m_LastPrime = new PrimesBigInteger(r.ToString());

            for (int i = 0; i < 1000; i++)
            {
                m_LastPrime = m_LastPrime.NextProbablePrime();
                if (m_LastPrime.ToString().Length != l) break;
                if (!m_GeneratedPrimes.Contains(m_LastPrime))
                {
                    m_GeneratedPrimes.Add(m_LastPrime);
                    return m_LastPrime;
                }
            }

            if (NonFurtherPrimeFound != null) NonFurtherPrimeFound();

            return m_LastPrime;
        }
Пример #26
0
        private void DoCalculatePrimitiveRoots()
        {
            try
            {
                DateTime start = DateTime.Now;

                FireOnStart();

                m_Jump = false;

                int numberOfPrimes = 0;

                foreach (var interval in intervals)
                {
                    PrimesBigInteger prime = interval[0];
                    if (!prime.IsPrime(10))
                    {
                        prime = prime.NextProbablePrime();
                    }
                    for (; prime.CompareTo(interval[1]) <= 0; prime = prime.NextProbablePrime())
                    {
                        numberOfPrimes++;

                        int row1 = log.NewLine();
                        int row2 = log.NewLine();

                        log.Info(string.Format(rsc.proot_calculating, prime.ToString()), 0, row1);

                        PrimesBigInteger primeMinus1 = prime.Subtract(PrimesBigInteger.One);
                        PrimesBigInteger numroots    = primeMinus1.Phi();

                        string fmt    = numroots.CompareTo(PrimesBigInteger.One) == 0 ? rsc.proot_resultcalc : rsc.proot_resultscalc;
                        string result = string.Format(fmt, prime.ToString(), numroots.ToString());
                        log.Info(result + ". " + rsc.proot_calculating, 0, row1);

                        PrimesBigInteger primitiveroot = PrimesBigInteger.One;
                        while (primitiveroot.CompareTo(prime) < 0)
                        {
                            if (m_Jump)
                            {
                                break;
                            }
                            if (IsPrimitiveRoot(primitiveroot, prime))
                            {
                                break;
                            }
                            primitiveroot = primitiveroot.Add(PrimesBigInteger.One);
                        }

                        List <PrimesBigInteger> roots = new List <PrimesBigInteger>();

                        PrimesBigInteger i       = PrimesBigInteger.One;
                        bool             skipped = false;

                        while (i.CompareTo(prime) < 0)
                        {
                            lock (m_JumpLockObject)
                            {
                                if (m_Jump)
                                {
                                    m_Jump  = false;
                                    skipped = true;
                                    break;
                                }
                            }
                            if (PrimesBigInteger.GCD(i, primeMinus1).Equals(PrimesBigInteger.One))
                            {
                                roots.Add(primitiveroot.ModPow(i, prime));
                            }
                            i = i.Add(PrimesBigInteger.One);
                        }

                        if (skipped)
                        {
                            log.Info(result + ". " + rsc.proot_skip, 0, row1);
                        }
                        else
                        {
                            log.Info(result + ". " + rsc.proot_printing, 0, row1);
                            roots.Sort(PrimesBigInteger.Compare);
                            //string numbers = string.Join(" ", roots.ToArray().Select(x => x.ToString()));
                            StringBuilder sb = new StringBuilder();
                            foreach (var r in roots)
                            {
                                lock (m_JumpLockObject)
                                {
                                    if (m_Jump)
                                    {
                                        m_Jump  = false;
                                        skipped = true;
                                        break;
                                    }
                                }
                                sb.Append(r.ToString() + " ");
                            }
                            if (skipped)
                            {
                                log.Info(result + ". " + rsc.proot_skip, 0, row1);
                            }
                            else
                            {
                                string numbers = sb.ToString();
                                log.Info(numbers, 0, row2);
                                log.Info(result + ":", 0, row1);
                            }
                        }

                        log.NewLine();
                    }
                }

                if (numberOfPrimes == 0)
                {
                    log.Info(rsc.proot_noprimes);
                }

                TimeSpan diff = DateTime.Now - start;

                StopThread();
            }
            catch (Exception ex)
            {
            }
        }
Пример #27
0
 public FactorizingException(PrimesBigInteger value, PrimesBigInteger maxValue)
     : base()
 {
     this.m_Message = string.Format("{0} is bigger than MaxValue {1}", new object[] { value.ToString(), maxValue.ToString() });
 }
Пример #28
0
        private void ExecuteRandomThread()
        {
            FireEventExecuteTest();

            int i = 1;

            for (; i <= m_Rounds; i++)
            {
                BigInteger k = BigIntegerHelper.Max(2, BigIntegerHelper.RandomIntLimit(BigInteger.Parse(m_RandomBaseTo.ToString())));
                if (ExecuteWitness(i, new PrimesBigInteger(k.ToString())))
                {
                    break;
                }
            }

            if (i <= m_Rounds)
            {
                log.Info(string.Format((i == 1) ? rsc.Primetest.mr_witnessfound1 : rsc.Primetest.mr_witnessfound2, i, m_Value));
            }
            else
            {
                log.Info(string.Format((m_Rounds.IntValue == 1) ? rsc.Primetest.mr_witnessnotfound1 : rsc.Primetest.mr_witnessnotfound2, m_Rounds.IntValue, m_Value));
            }

            FireEventCancelTest();
        }
Пример #29
0
 void generateNumberControlVertFree_OnRandomNumberGenerated(PrimesBigInteger value)
 {
     tbVertFree.Text = value.ToString();
     GetValue();
     //ValidateFreeInput(ref value);
 }
Пример #30
0
        public PrimesBigInteger GetValue()
        {
            PrimesBigInteger value = null;

            ResetMessages();

            if (m_RbSelection == Selection.Free)
            {
                ValidateFreeInput(ref value);
            }
            else if (m_RbSelection == Selection.Calc)
            {
                ValidateCalcInput(ref value);
            }

            if (value != null)
            {
                SetButtonExecuteButtonEnabled(true);
                if (m_ValueValidators.ContainsKey(Value))
                {
                    IValidator <PrimesBigInteger> validator = m_ValueValidators[Value];
                    validator.Value = value.ToString();
                    Primes.WpfControls.Validation.ValidationResult result = validator.Validate(ref value);
                    if (result != Primes.WpfControls.Validation.ValidationResult.OK)
                    {
                        switch (result)
                        {
                        case Primes.WpfControls.Validation.ValidationResult.WARNING:
                            if (m_RbSelection == Selection.Calc)
                            {
                                InfoCalc(validator.Message, new TextBox[] { m_tbCalcBase, m_tbCalcExp, m_tbCalcFactor, m_tbCalcSum }, validator.HelpLink);
                            }
                            else
                            {
                                InfoFree(validator.Message, m_tbFree, validator.HelpLink);
                            }
                            SetButtonExecuteButtonEnabled(false);

                            break;

                        case Primes.WpfControls.Validation.ValidationResult.ERROR:
                            if (m_RbSelection == Selection.Calc)
                            {
                                ErrorCalc(validator.Message, new TextBox[] { m_tbCalcBase, m_tbCalcExp, m_tbCalcFactor, m_tbCalcSum }, validator.HelpLink);
                            }
                            else
                            {
                                ErrorFree(validator.Message, m_tbFree, validator.HelpLink);
                            }
                            SetButtonExecuteButtonEnabled(false);
                            break;

                        default:
                            break;
                        }
                        return(null);
                    }
                }
                foreach (IValidator <PrimesBigInteger> validator in this.m_SingleAdvisors[Value])
                {
                    if (validator.Validate(ref value) != Primes.WpfControls.Validation.ValidationResult.OK)
                    {
                        if (m_RbSelection == Selection.Free)
                        {
                            InfoFree(validator.Message, new TextBox[] { m_tbFree }, validator.HelpLink);
                        }
                        else if (m_RbSelection == Selection.Calc)
                        {
                            InfoFree(validator.Message, new TextBox[] { m_tbCalcFactor, m_tbCalcBase, m_tbCalcExp, m_tbCalcSum }, validator.HelpLink);
                        }
                        break;
                    }
                }
            }
            else
            {
                SetButtonExecuteButtonEnabled(false);
            }
            return(value);
        }