Exemple #1
0
        public static void H()
        {
            Console.WriteLine("(G) Using CompNum method.");
            Console.WriteLine("Comparing between zeroes.");
            BigNum bigNumH1 = new BigNum();
            BigNum bigNumH2 = new BigNum();

            bigNumH1.CompNum(bigNumH2);

            Console.WriteLine("Comparing between 8 and 16.");
            BigNum bigNumH3 = new BigNum(8L);
            BigNum bigNumH4 = new BigNum(16L);

            bigNumH3.CompNum(bigNumH4);

            Console.WriteLine("Comparing between 32 and 32.");
            BigNum bigNumH5       = new BigNum(32L);
            BigNum bigNumH6       = new BigNum();
            var    positionsOf1sH = new List <int> {
                394
            };

            bigNumH6.ReadNum(positionsOf1sH);
            bigNumH5.CompNum(bigNumH6);

            Console.WriteLine();
        }
Exemple #2
0
        public static void IIC()
        {
            Console.WriteLine("III.");
            Console.WriteLine("Using RSA");

            //BigNum b = new BigNum();
            //List<int> bPositionsOf1s = new List<int>
            //{
            //     GlobalVariables.MAX_NUM - 16 - 1,
            //     GlobalVariables.MAX_NUM - 1
            //};
            //b.ReadNum(bPositionsOf1s);

            BigNum     b = new BigNum();
            List <int> bPositionsOf1s = new List <int>
            {
                GlobalVariables.MAX_NUM - 5 - 1,
                GlobalVariables.MAX_NUM - 1
            };

            b.ReadNum(bPositionsOf1s);
            Console.Write("b = ");
            MathOps.PrintNumberInPowersOfTwo(b);

            BigNum     plainText = new BigNum();
            List <int> plainTextPositionsOf1s = new List <int>
            {
                GlobalVariables.MAX_NUM - 197 - 1,
                GlobalVariables.MAX_NUM - 100 - 1,
                GlobalVariables.MAX_NUM - 50 - 1,
                GlobalVariables.MAX_NUM - 6 - 1,
                GlobalVariables.MAX_NUM - 1 - 1
            };

            plainText.ReadNum(plainTextPositionsOf1s);
            Console.Write("Encrypting the number: ");
            MathOps.PrintNumberInPowersOfTwo(plainText);

            BigNum cipherText = new BigNum();
            BigNum a          = new BigNum();
            BigNum n          = new BigNum();
            BigNum p          = new BigNum();
            BigNum q          = new BigNum();

            Console.WriteLine("Generating RSA");
            MathOps.GenRSA(b, a, p, q, n);
            Console.WriteLine("Encrypting plaintext to:");
            cipherText = MathOps.Encrypt(plainText, b, n);
            MathOps.PrintNumberInPowersOfTwo(cipherText);

            Console.WriteLine("Decrypting ciphertext to:");
            BigNum decryptedText = MathOps.Decrypt(cipherText, a, n);

            MathOps.PrintNumberInPowersOfTwo(decryptedText);

            plainText.CompNum(decryptedText);

            Console.WriteLine();
        }