コード例 #1
0
        public Decipher()
        {
            this.N   = GenerateMonocyclicTransposition.ReadParametrN();
            this.Key = ReadKey();
            if (this.Key == null || this.Key.Length != N)
            {
                Console.WriteLine("Error: key.txt");
                return;
            }
            String cryptogram = ReadCryptogram();

            if (cryptogram == null)
            {
                Console.WriteLine("Error: cryptogram.txt");
                return;
            }

            StringBuilder decipher = new StringBuilder();
            Random        random   = new Random();
            int           position = 0;

            while (position < cryptogram.Length)
            {
                String partCryptogram = cryptogram.Substring(position, this.N);
                char[] temp           = new char[this.N];
                for (int i = 0; i < this.N; i++)
                {
                    temp[i] = partCryptogram[Key[i] - 1];
                }
                decipher.Append(temp);
                position += this.N;
            }
            PrintDecipher(decipher.ToString());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: oksbelysheva/SSU
        public static void Main(string[] args)
        {
            Console.WriteLine("1 - Сгенерировать случайную моноциклическую перестановку\n" +
                              "2 - Зашифровать текст шифром простой перестановки\n" +
                              "3 - Расшифровать текст при помощи известного ключа\n" +
                              "4 - Выполнить тест Казиски\n" +
                              "5 - По полученной длине ключа из теста Казиски, восстановить сообщение");
            int choice = int.Parse(Console.ReadLine());

            switch (choice)
            {
            case 1:
            {
                GenerateMonocyclicTransposition transposition = new GenerateMonocyclicTransposition();
                break;
            }

            case 2:
            {
                Cryptogram cryptogram = new Cryptogram();
                break;
            }

            case 4:
            {
                Kasiski kasiski1 = new Kasiski(7);
                Kasiski kasiski2 = new Kasiski(5);
                Kasiski kasiski3 = new Kasiski(6);
                int     temp     = GCD(kasiski1.answer, kasiski2.answer);
                int     result   = GCD(temp, kasiski3.answer);
                File.WriteAllText("anticipatedN.txt", result.ToString());
                break;
            }

            case 3:
            {
                Decipher decipher = new Decipher();
                break;
            }

            case 5:
            {
                GenerateAllMonocyclicTransposition generateAllMonocyclicTransposition = new GenerateAllMonocyclicTransposition();
                break;
            }
            }
        }
コード例 #3
0
ファイル: Cryptogram.cs プロジェクト: oksbelysheva/SSU
        public Cryptogram()
        {
            this.N   = GenerateMonocyclicTransposition.ReadParametrN();
            this.Key = ReadKey();
            if (this.Key == null || this.Key.Length != N)
            {
                Console.WriteLine("Error: key.txt");
                return;
            }
            String message = ReadMessage();

            if (message == null)
            {
                Console.WriteLine("Error: message.txt");
                return;
            }

            StringBuilder cryptograma = new StringBuilder();

            Random random   = new Random();
            int    position = 0;

            for (int i = 0; i <= message.Length % this.N; i++)
            {
                //message = message + (message[new Random().Next(0, message.Length)]);
                message = message + " ";
            }

            while (position < message.Length)
            {
                String partDecipher = message.Substring(position, this.N);
                char[] temp         = new char[this.N];
                for (int i = 0; i < this.N; i++)
                {
                    temp[Key[i] - 1] = partDecipher[i];
                }
                cryptograma.Append(temp);
                position += this.N;
            }



            PrintCryptogram(cryptograma.ToString());
        }