예제 #1
0
        /// <summary>
        /// S (N) parameter
        /// </summary>
        /// <returns>return Lcm between Legendre</returns>
        private BigInteger GetLcm()
        {
            BigInteger      d = GetD();
            LegendreNumbers legendresNumbers = new LegendreNumbers(d, PrimeNumbers.Q, PrimeNumbers.P);

            int a = PrimeNumbers.P - legendresNumbers.Dp;
            int b = PrimeNumbers.Q - legendresNumbers.Dq;

            return(MathNet.Numerics.Euclid.LeastCommonMultiple(a, b));
        }
예제 #2
0
        public void PrivateKey()
        {
            LucPrime   lucPrime = new LucPrime(p: 1949, q: 2089);
            BigInteger message  = 11111;

            LucPublicKey    publicKey = new LucPublicKey(1103, 4071461);
            LegendreNumbers legend    = new LucasSequences.LegendreNumbers(lucPrime, message);
            LucPrivateKey   key       = new LucPrivateKey(publicKey, legend);

            Assert.AreEqual <BigInteger>(key.d, 24017);
        }
예제 #3
0
        public void LegandNumbers()
        {
            //int
            LucPrime   lucPrime = new LucPrime(p: 1949, q: 2089);
            BigInteger message  = 11111;

            LegendreNumbers legend = new LucasSequences.LegendreNumbers(lucPrime, message);

            Assert.AreEqual <Int32>(lucPrime.N, 4071461);
            Assert.AreEqual <BigInteger>(legend.D, 123454317);
            Assert.AreEqual <int>(legend.Dp, -1);
            Assert.AreEqual <int>(legend.Dq, -1);
            Assert.AreEqual(legend.Sn, 407550);
        }
예제 #4
0
        public void EncryptMessageMod()
        {
            AAtkin     a        = new AAtkin(1350);
            LucPrime   lucPrime = new LucPrime(a.RandomPrime, a.RandomPrime);
            BigInteger message  = 11111;

            LegendreNumbers legendreNumbers = new LucasSequences.LegendreNumbers(primeNumbers: lucPrime, message: message);
            LucPublicKey    publicKey       = new LucPublicKey(lucPrime);
            LucPrivateKey   privateKey      = new LucPrivateKey(publicKey, legendreNumbers);

            var seqPublic = new LucasSequences.LucasSequence(message, 1);

            var ciphertext = seqPublic[publicKey.e, publicKey.N];

            var seqPrivate = new LucasSequences.LucasSequence(ciphertext, 1);

            var result = seqPrivate[privateKey.d, privateKey.N];

            Assert.AreEqual <BigInteger>(result, message);
        }
예제 #5
0
        public LucPrivateKey(LucPublicKey publicKey, LegendreNumbers legendreNumbers)
        {
            d = BigInteger.ModPow(publicKey.e, (int)(legendreNumbers.Sn.Eyler() - 1), legendreNumbers.Sn);

            N = publicKey.N;
        }