Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DetectiveBoev
- {
- class DetectiveBoev
- {
- static void Main(string[] args)
- {
- string secretWord = Console.ReadLine(); // We create a console readable variable for the secret word.
- string encryptedMsg = Console.ReadLine(); // We create a console readable variable for the encrypted message.
- int wordSum = 0; // Create a int var to hold the sum from each char in the secret word.
- int mask = 0; // The int var,named mask holds the sum of the sum of chars in the secret word.
- string decryptedMsg = ""; // This string var holds empty value of the decrypted message,which we'll use later.
- for (int i = 0; i < secretWord.Length; i++) // This for loop gets the sum of the chars in the secret word and ends when we get to the end of secret word.
- {
- wordSum += secretWord[i]; // The wordSum holds the value of the each symbol in the char array of secretWord. e.g: secretWord = "code",then wordSum = 99 + 111 + 100 + 101 = 411.
- }
- while (wordSum > 9) // 411 > 9; Entering in the loop.
- {
- while (wordSum > 0) //411 > 0; Entering in the inner loop.
- {
- mask += wordSum % 10; // The mask is 0,so we take the value of the wordSum and divide by 10 with reminder and add it to the mask.
- wordSum /= 10; // Divide wordSum by 10.
- }
- wordSum = mask; //The value of wordSum is now equal to value of the mask.
- }
- for (int i = 0; i < encryptedMsg.Length; i++) // Make 2nd for loop to decrypt the messige.
- {
- if (encryptedMsg[i] % mask == 0) // We make if statement to check every symbol in the char array of the encryptedMsg is dividing by the mask without reminder.
- {
- decryptedMsg += (char)(mask + encryptedMsg[i]); // If it's so. We apply the value of the CASTED to char encryptedMsg symbol of the array + mask.
- }
- else // if not.
- {
- decryptedMsg += (char)(encryptedMsg[i] - mask); // We apply the value ot the CASTED to char encrptedMsg symbol of the array - mask.
- }
- }
- for (int i = decryptedMsg.Length - 1; i >= 0; i--) // This is the loop that reversing the message. The i has a value of the decryptedMsg - 1,and we stop the loop when i has a value of 0 or higher.
- {
- Console.Write(decryptedMsg[i]); // This print one char of decryptedMsg each loop.
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement