Пример #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
        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());
        }