Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication
- {
- class Program
- {
- //абвгдеёжзийклмнопрстуфхцчшщъыьэюя
- static string secretWord=string.Empty;
- static string cryptWord=string.Empty;
- static int [] secretInt;
- static bool exit = false;
- static void Main ( string [] args )
- {
- Console.WriteLine ( "Для шифровки сообщения нажмите клавишу \"C\"" );
- Console.WriteLine ( "Для шифровки сообщения нажмите клавишу \"E\"" );
- Console.WriteLine ( "Для шифровки сообщения нажмите клавишу \"Esc\"" );
- while (!exit )
- {
- Menu ();
- }
- }
- public static char TranslateChar ( char currentSymbol, int translation, char minSymbol = 'а', char maxSymbol = 'я' )
- {
- translation = (translation - minSymbol);
- if ( currentSymbol >= minSymbol & currentSymbol <= maxSymbol )
- {
- currentSymbol = Convert.ToChar ( currentSymbol + translation );
- if ( currentSymbol < minSymbol )
- {
- currentSymbol = Convert.ToChar ( maxSymbol - ( minSymbol - currentSymbol - 1 ) );
- }
- else if ( currentSymbol > maxSymbol )
- {
- currentSymbol = Convert.ToChar( minSymbol + ( currentSymbol - maxSymbol - 1 ) );
- }
- return Convert.ToChar ( currentSymbol );
- }
- return currentSymbol;
- }
- static char Crypt ( char crypt, int shift )
- {
- return TranslateChar ( crypt, shift );
- }
- static int [] CryptWord ( string word )
- {
- char [] symbols = word.ToCharArray ();
- int [] secretInt = new int [word.Length];
- for ( int i = 0 ; i < word.Length ; i++ )
- {
- secretInt [i] = Convert.ToInt32 ( symbols [i] );
- }
- return secretInt;
- }
- static string Crypting ( string stringForCrypting, string cryptingWord )
- {
- secretWord = stringForCrypting;
- cryptWord = cryptingWord;
- secretInt = CryptWord( cryptWord );
- int step;
- string cryptedString = "";
- for ( int i = 0 ; i < secretWord.Length ; i++ )
- {
- if ( i < cryptWord.Length )
- {
- step = secretInt [i];
- cryptedString += Crypt ( secretWord[i], step );
- }
- else
- {
- int ind = ( cryptingWord.Length - ( i % cryptingWord.Length ) )-1;
- step = secretInt [ind];
- cryptedString += Crypt ( secretWord[i], step );
- }
- }
- return cryptedString;
- }
- static string Encrypting ( string encryptingWord )
- {
- if ( encryptingWord == cryptWord )
- {
- return secretWord;
- }
- else
- {
- return "Неверное слово: ";
- }
- }
- static void Menu ()
- {
- ConsoleKeyInfo key = Console.ReadKey (true);
- switch ( key.Key )
- {
- case ConsoleKey.C:
- Console.Write ( "Введите слово для шифровки и слово которым будет произведена шифровка: " );
- Console.WriteLine ( Crypting ( Console.ReadLine (), Console.ReadLine () ) );
- break;
- case ConsoleKey.E:
- Console.Write ( "Введите секретное слово: " );
- Console.WriteLine ( Encrypting ( Console.ReadLine () ) );
- break;
- case ConsoleKey.Escape:
- exit = true;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement