Esempio n. 1
0
        public void TrefferBestimmenTest2()
        {
            int[] zahlensysteme = new int[] { 3, 4, 5, 7 };
            int[] primA         = new int[] { 29, 109, 2087, 3253, 6449, 9697 };
            int[] primB         = new int[] { 31, 139, 3251, 4799, 7757, 9973 };

            for (int i = 0; i < primA.Length; i++)
            {
                for (int j = 0; j < primB.Length; j++)
                {
                    BigInteger    n      = primA[i] * primB[j];
                    List <Zyklus> result = FermatExtended.TrefferBestimmen(n, zahlensysteme);
                    var           wurzel = Helper.Wurzel(n);

                    long mExpected = ((long)primA[i] + (long)primB[j]) / 2;
                    for (int k = 0; k < result.Count; k++)
                    {
                        long offset = (mExpected - (long)wurzel.Item1 - 1) / result[k].ZyklusSumme;
                        bool bFound = result[k].Exists(x => ((offset * result[k].ZyklusSumme) + x) == (mExpected - (long)wurzel.Item1 - 1));

                        Assert.IsTrue(bFound);
                    }
                }
            }
        }
Esempio n. 2
0
        public void TrefferBestimmenGrobTest()
        {
            int n = 499 * 41;

            List <Zyklus> result = FermatExtended.TrefferBestimmen(n, new int[] { 10 });

            List <FermatExtended.MddPaarImZahlensystem> paare = FermatExtended.mdPaareBestimmen(n, new int[] { 10 });

            List <Tuple <int, int, int> > vergleichsliste = new List <Tuple <int, int, int> >();

            int m = (int)Math.Sqrt(n) + 1;

            FermatExtended.MddPaarImZahlensystem aktuellesPaar = paare[0];
            for (int i = 0; i < (aktuellesPaar.Zahlensystem); i++)
            {
                int dd = m * m - n;
                if (aktuellesPaar.MddPaar.Exists(x => ((x.Item1 == m % aktuellesPaar.Zahlensystem) && (x.Item2 == dd % aktuellesPaar.Zahlensystem))))
                {
                    vergleichsliste.Add(new Tuple <int, int, int>(m % aktuellesPaar.Zahlensystem, dd % aktuellesPaar.Zahlensystem, i));
                }

                m++;
            }
            vergleichsliste.Add(new Tuple <int, int, int>(0, 0, aktuellesPaar.Zahlensystem + vergleichsliste[0].Item3));

            Zyklus aktuellerZyklus = result[0];

            for (int i = 0; i < aktuellerZyklus.NumberOfElements; i++)
            {
                Assert.IsTrue(vergleichsliste[i].Item3 == aktuellerZyklus.Elemente[i]);
            }
        }
        public void EndgueltigenZyklusBestimmenTest()
        {
            int[] zahlensysteme = new int[]
            {
                2, 2 * 2, 2 * 2 * 2, 2 * 2 * 2 * 2, 2 * 2 * 2 * 2 * 2, 2 * 2 * 2 * 2 * 2 * 2,
                3, 3 * 3, 3 * 3 * 3, 3 * 3 * 3 * 3, 3 * 3 * 3 * 3 * 3, 3 * 3 * 3 * 3 * 3 * 3,
                5, 5 * 5, 5 * 5 * 5, 5 * 5 * 5 * 5,
                7, 7 * 7, 7 * 7 * 7, 7 * 7 * 7 * 7,
                11, 11 * 11, 11 * 11 * 11,
                13, 13 * 13, 13 * 13 * 13,
            };
            int a = 29;
            int b = 31;

            // 3, 4, 5, 7, 11, 13, 17, 19, .. 23
            // int[] zahlensysteme = new int[] { 9, 16, 25, 49, 121, 169, 289, 361 };
            // int a = 29;
            // int b = 31;

            Zyklus actual = FermatExtended.EndgueltigenZyklusBestimmen(new BigInteger(a * b), zahlensysteme);

            SortZyklus(ref actual, a * b);

            Assert.IsTrue(actual.NumberOfElements == 45);
            Assert.IsTrue(actual.ZyklusSumme == 2310);
        }
        private static void Check(BigInteger n, int zahlensystem)
        {
            int potenz = zahlensystem;

            List <Tuple <int, int> > actual = FermatExtended.EndungenBestimmen(n, zahlensystem);

            BigInteger sh;

            BigInteger.DivRem(n, potenz, out sh);
            int vergleichswert = (int)sh;

            List <Tuple <int, int> > expected = new List <Tuple <int, int> >();

            for (int i = 0; i < potenz; i++)
            {
                for (int j = i; j < potenz; j++)
                {
                    if (((i * j) % potenz) == vergleichswert)
                    {
                        expected.Add(new Tuple <int, int>(i, j));
                    }
                }
            }


            Assert.IsTrue(actual.Count == expected.Count);

            foreach (Tuple <int, int> currentItem in expected)
            {
                // also include "switched" values
                Assert.IsTrue(actual.Exists(x => ((x.Item1 == currentItem.Item1) && (x.Item2 == currentItem.Item2)) || ((x.Item1 == currentItem.Item2) && (x.Item2 == currentItem.Item1))));
            }
        }
Esempio n. 5
0
        private FermatExtended.MddPaarImZahlensystem BerechneMDInternal(int n, int zahlensystem)
        {
            int m;
            int d1;
            int d2;
            int dd;

            //int potenz = zahlensystem * zahlensystem;

            FermatExtended.MddPaarImZahlensystem mddPaareImZahlensystem = new FermatExtended.MddPaarImZahlensystem(zahlensystem);

            List <Tuple <int, int> > endungen = FermatExtended.EndungenBestimmen(n, zahlensystem);

            foreach (Tuple <int, int> endung in endungen)
            {
                // aller Wahrscheinlichkeit nach reichen zwei Überprüfungen
                // 0*10**1+X+Y
                // 1*10**1+X+Y
                for (int i = 0; i < zahlensystem; i++)
                {
                    for (int j = 0; j < zahlensystem; j++)
                    {
                        m  = ((((i * zahlensystem) + endung.Item1) + ((j * zahlensystem) + endung.Item2)) / 2) % zahlensystem;
                        d1 = ((((i * zahlensystem) + endung.Item1) - ((j * zahlensystem) + endung.Item2)) / 2) % zahlensystem;
                        d2 = ((((i * zahlensystem) + endung.Item2) - ((j * zahlensystem) + endung.Item1)) / 2) % zahlensystem;

                        if (d1 < 0)
                        {
                            d1 += zahlensystem;
                        }

                        if (d2 < 0)
                        {
                            d2 += zahlensystem;
                        }


                        // pruefen, ob "m" eine Ganzzahl geblieben ist, sonst kann das Ergebnis verworfen werden
                        if (((2 * m) % zahlensystem) == (((i * zahlensystem) + endung.Item1) + ((j * zahlensystem) + endung.Item2)) % zahlensystem)
                        {
                            dd = (d1 * d1) % zahlensystem;
                            if (!mddPaareImZahlensystem.MddPaar.Exists(x => x.Item1 == m && x.Item2 == dd))
                            {
                                mddPaareImZahlensystem.MddPaar.Add(new Tuple <int, int>(m, dd));
                            }

                            dd = (d2 * d2) % zahlensystem;
                            if (!mddPaareImZahlensystem.MddPaar.Exists(x => x.Item1 == m && x.Item2 == dd))
                            {
                                mddPaareImZahlensystem.MddPaar.Add(new Tuple <int, int>(m, dd));
                            }
                        }
                    }
                }
            }

            return(mddPaareImZahlensystem);
        }
Esempio n. 6
0
        public void mdPaareBestimmenTest()
        {
            int zahlensystem = 10;
            int n            = 43 * 971;

            List <FermatExtended.MddPaarImZahlensystem> actual = FermatExtended.mdPaareBestimmen(n, new int[] { zahlensystem });

            FermatExtended.MddPaarImZahlensystem expected = this.BerechneMDInternal(n, zahlensystem);


            Assert.IsTrue(actual[0].MddPaar.Count == expected.MddPaar.Count);

            for (int i = 0; i < expected.MddPaar.Count; i++)
            {
                Assert.IsTrue(actual[0].MddPaar.Exists(x => ((x.Item1 == expected.MddPaar[i].Item1) && (x.Item2 == expected.MddPaar[i].Item2))));
            }
        }
        public void RunTest()
        {
            int[] zahlensysteme = new int[] { 3, 4, 5, 7, 11 };
            int[] primA         = new int[] { 29, 109, 2087, 3253, 6449, 9697 };
            int[] primB         = new int[] { 31, 139, 3251, 4799, 7757, 9973 };


            for (int i = 0; i < primA.Length; i++)
            {
                for (int j = 0; j < primB.Length; j++)
                {
                    var actual = FermatExtended.Run(new BigInteger(primA[i] * primB[j]), zahlensysteme);
                    if (actual.Item1 == primA[i])
                    {
                        Assert.IsTrue(actual.Item1 == primA[i] && actual.Item2 == primB[j], string.Format("Erhalten: '{0}' '{1}'. Erwartet: '{2}' '{3}'.", actual.Item1, actual.Item2, primA[i], primB[j]));
                    }
                    else
                    {
                        Assert.IsTrue(actual.Item2 == primA[i] && actual.Item1 == primB[j], string.Format("Erhalten: '{0}' '{1}'. Erwartet: '{2}' '{3}'.", actual.Item1, actual.Item2, primA[i], primB[j]));
                    }
                }
            }
        }