-
-
Save zdgeorgiev/0b7cb678efb670a68319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string maskString = Console.ReadLine(); | |
int maskAsInt = 0; | |
for (int i = 0; i < maskString.Length; i++) | |
{ | |
maskAsInt += (int)maskString[i]; | |
} | |
int maskInt = getOnlyNumber(maskAsInt); | |
string encrypted = Console.ReadLine(); | |
StringBuilder output = new StringBuilder(); | |
for (int i = 0; i < encrypted.Length; i++) | |
{ | |
if ((int)encrypted[i] % maskInt == 0) | |
{ | |
output.Append((char)((int)encrypted[i] + maskInt)); | |
} | |
else | |
{ | |
output.Append((char)((int)encrypted[i] - maskInt)); | |
} | |
} | |
for (int i = 0; i < output.Length; i++) | |
{ | |
Console.Write(output[output.Length - 1 - i]); | |
} | |
Console.WriteLine(); | |
} | |
private static int getOnlyNumber(int maskString) | |
{ | |
int sum = 0; | |
while (maskString > 0) | |
{ | |
sum += maskString % 10; | |
maskString /= 10; | |
} | |
if (sum >= 10) | |
{ | |
return getOnlyNumber(sum); | |
} | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment