Exemple #1
0
        static void Main(string[] args)
        {
            DeleteOldFiles();

            var fileName = ConsoleMessager.AskFilename();

            // converting a file to binary sequence
            var binaryFile = FileWorker.GetBinaryFile(fileName);

            // generating a key
            var binaryKey = GenerateKey(binaryFile.Count);

            // ask series length
            var k = ConsoleMessager.AskBlockLength(binaryFile.Count);

            // frequency test for key
            binaryKey = FrequencyTest(binaryKey, k, "key");

            // frequency test for file before any manipulation
            FrequencyTest(binaryFile, k, "file before encryption");

            // a number to divide key length on it
            var number = ConsoleMessager.AskKeyDivideOnNumber();

            // vername manipulations
            var cryptedFile = CypherLogic(binaryKey.GetRange(0, binaryKey.Count / number), binaryFile, fileName);

            // Frequency test for encrypted file
            FrequencyTest(cryptedFile, k, "file after encryption");

            // Corelation tests
            CorelationTest(binaryKey, "key");
            CorelationTest(binaryFile, "file before encryption");
            CorelationTest(cryptedFile, "file after encryption");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // Ask user key length
            var keyLength = ConsoleMessager.AskKeyLength();

            Console.WriteLine("Now input number (number p will be increased on  this number, q will be decreased on this number):");
            var keyChange = (int)ConsoleMessager.AskRate();

            var keysGenerationTime = new Stopwatch();

            keysGenerationTime.Start();

            // generating of public, private key and cypher module
            var keys = GenerateKeys(keyLength, keyChange);

            keysGenerationTime.Stop();
            Console.WriteLine(String.Format("Key generation time: {0} sec", (double)keysGenerationTime.ElapsedMilliseconds / 1000));
            Console.WriteLine("-------------------------------------------------------------");

            // ask file name which will be encrypted
            var fileName = ConsoleMessager.AskFilename();

            // Rsa encrypting
            RsaCrypt(keys, fileName, keyLength);

            //var a = BigInteger.Parse(Console.ReadLine());
            //RsaBreaking(a);

            // trying to break cypher module
            RsaBreaking(keys.cypherModule);
        }