Skip to content

Instantly share code, notes, and snippets.

@zdgeorgiev
Created July 14, 2015 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdgeorgiev/0b7cb678efb670a68319 to your computer and use it in GitHub Desktop.
Save zdgeorgiev/0b7cb678efb670a68319 to your computer and use it in GitHub Desktop.
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