Example #1
0
        //Generates the modulus using more thread
        private static BigInteger ParGenMod(GeneratorWrap gen, uint wordSize, int threads, uint precision)
        {
            IPrime mainGenerator, workerGenerator;

            //threads distribution for primes creation
            if (threads < 4)
            {
                mainGenerator   = new SequentialPrime(gen.GetInt(), precision, wordSize);
                workerGenerator = new SequentialPrime(gen.GetInt(), precision, wordSize);
            }
            else
            {
                mainGenerator   = new ParallelPrime(gen.GetInt(), precision, wordSize, threads - threads / 2);
                workerGenerator = new ParallelPrime(gen.GetInt(), precision, wordSize, threads / 2);
            }

            //primes creation
            var firstPrime  = gen.GetBig();
            var secondPrime = gen.GetBig();

            while (!SecurityCheck(firstPrime, secondPrime))
            {
                secondPrime = gen.GetBig();
            }

            var worker = new Task <BigInteger>(() => workerGenerator.NextPrime(firstPrime));

            worker.Start();
            secondPrime = mainGenerator.NextPrime(secondPrime);

            worker.Wait();
            firstPrime = worker.Result;
            worker.Dispose();

            return(firstPrime * secondPrime);
        }
Example #2
0
        //Generates the modulus using one thread
        private static BigInteger SeqGenMod(GeneratorWrap gen, uint wordSize, uint precision)
        {
            IPrime generator   = new SequentialPrime(gen.GetInt(), precision, wordSize);
            var    firstPrime  = gen.GetBig();
            var    secondPrime = gen.GetBig();

            while (!SecurityCheck(firstPrime, secondPrime))
            {
                secondPrime = gen.GetBig();
            }

            firstPrime  = generator.NextPrime(firstPrime);
            secondPrime = generator.NextPrime(secondPrime);

            return(firstPrime * secondPrime);
        }