コード例 #1
0
ファイル: Program.cs プロジェクト: ReyyL/Lab1-RSA
        private static void Encode()
        {
            Console.Write("Enter first prime number: ");
            var p = new Integer(Console.ReadLine());

            Console.Write("Enter second prime number: ");
            var q      = new Integer(Console.ReadLine());
            var module = p * q;

            Console.WriteLine($"Your module is {module}");
            var phi            = (p - Integer.One) * (q - Integer.One);
            var publicExponent = RSA.CalculatePublicExponent(phi);
            var secretExponent = RSA.CalculateSecretExponent(publicExponent, phi);

            Console.WriteLine($"Your module {module}");
            Console.WriteLine($"Your secret exponent {secretExponent}");
            var message =
                File.ReadAllBytes(@"C:\Users\Egor\Desktop\Integers\RSAFileCrypter\ToEncode.txt")
                .Select(x => (int)x);
            var encoded = RSA.Encode(message, publicExponent, module);

            foreach (var integer in encoded)
            {
                Console.WriteLine(integer.ToString());
            }
        }