Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Sixth
- {
- const string alphabet = "abcdefghijklmnopqrstuvwxyz"; // объявление константы
- static void Main(string[] args)
- {
- int quantity, shift;
- string word; // объявление переменных
- string ciphtext;
- if (!int.TryParse(Console.ReadLine(), out quantity) || quantity <= 0 || !int.TryParse(Console.ReadLine(), out shift)) // проверка верности введенных данных
- {
- Console.WriteLine("wrong"); // сообщение об ошибке
- return; // заавершение работы программы
- }
- Checking(quantity, shift); // вызов метода
- }
- static void Caesar(string word, int shift, out string ciphtext) // метод раскрытия шифра Цезаря
- {
- shift %= 26; // объявление переменных
- ciphtext = "";
- for (int i = 0; i < word.Length; i++)
- {
- char ch = word[i];
- int index = alphabet.IndexOf(ch); // расчеты
- if (index < 0)
- {
- ciphtext += ch.ToString();
- }
- else
- {
- int SecondIndex = (alphabet.Length + index + shift) % alphabet.Length;
- ciphtext += alphabet[SecondIndex];
- }
- }
- Console.WriteLine(ciphtext);
- }
- static void Checking(int quantity, int shift) // объявление метода проверки
- {
- string word; // объявление переменных
- string ciphtext;
- for (int i = 0; i < quantity; i++)
- {
- word = Console.ReadLine();
- for (int r = 0; r < word.Length; r++)
- {
- char ch2 = word[r];
- if (ch2 < 97 || ch2 > 122)
- {
- Console.WriteLine("wrong"); // сообщение об ошибке
- return; // завершание работы программы
- }
- }
- Caesar(word, shift, out ciphtext); // вызов метода
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement