Advertisement
Guest User

Untitled

a guest
Jul 13th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class DetectiveBoev
  8. {
  9.     static void Main()
  10.     {
  11.         string secretWord = Console.ReadLine();
  12.         string encryptedMessage = Console.ReadLine();
  13.        
  14.         int mask = 0;
  15.         for (int i = 0; i < secretWord.Length; i++)
  16.             {
  17.                 mask += secretWord[i];
  18.             }
  19.        
  20.         while (mask > 9)
  21.         {
  22.             mask = CalcMask(mask);            
  23.         }
  24.                
  25.         char[] arr = encryptedMessage.ToCharArray();
  26.         for (int i = 0; i < arr.Length; i++)
  27.  
  28.         {
  29.             if (arr[i] % mask == 0)
  30.             {
  31.                 arr[i] = (char)(arr[i] + mask);
  32.             }
  33.             else
  34.             {
  35.                 arr[i] = (char)(arr[i] - mask);
  36.             }
  37.         }
  38.  
  39.         arr = arr.Reverse().ToArray();
  40.         Console.WriteLine(new string(arr));
  41.        
  42.     }
  43.  
  44.     private static int CalcMask(int mask)
  45.     {
  46.         int sum = 0;
  47.         while (mask > 0)
  48.         {
  49.            
  50.             sum += mask % 10;
  51.             mask = mask / 10;
  52.            
  53.         }
  54.         return sum;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement