Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class DetectiveBoev
- {
- static void Main()
- {
- string secretWord = Console.ReadLine();
- string encryptedWord = Console.ReadLine();
- int secretWordResult = Mask(secretWord, secretWord.Length - 1);
- int secretWordToMask = ResultMask(secretWordResult);
- Console.WriteLine(EncryptMsg(encryptedWord, secretWordToMask));
- }
- private static string EncryptMsg(string msg, int divide)
- {
- string msgResut = string.Empty;
- for (int i = msg.Length - 1; i >= 0; i--)
- {
- char check = msg[i] % divide == 0 ? (char)(msg[i] + divide) : (char)(msg[i] - divide);
- msgResut += check;
- }
- return msgResut;
- }
- private static int Mask(string mask, int lenght)
- {
- if (lenght == 0)
- {
- return mask[0];
- }
- return mask[lenght] + Mask(mask, lenght - 1);
- }
- private static int ResultMask(int result)
- {
- int returnNumber = 0;
- int singleDigit = 0;
- while (result != 0)
- {
- returnNumber += result % 10;
- result /= 10;
- }
- if (returnNumber > 9)
- {
- while (returnNumber > 9)
- {
- singleDigit += returnNumber % 10;
- returnNumber /= 10;
- singleDigit += returnNumber;
- }
- return singleDigit;
- }
- else
- {
- return returnNumber;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement