Skip to content

Instantly share code, notes, and snippets.

@borko9696
Created July 14, 2015 21:59
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 borko9696/4c99d9d8b694fb239869 to your computer and use it in GitHub Desktop.
Save borko9696/4c99d9d8b694fb239869 to your computer and use it in GitHub Desktop.
using System;
class Program
{
static void Main()
{
string secretWord =Console.ReadLine();
string msg = Console.ReadLine();
int sum = 0;
int mask = 0;
int newMask = 0;
char[] code = secretWord.ToCharArray();
char[] message = msg.ToCharArray();
string nonRevercedMsg = "";
for (int i = 0; i < code.Length; i++)
{
sum += code[i];
}
do
{
mask = 0;
while (sum > 0)
{
mask += sum % 10;
sum /= 10;
}
sum = mask;
} while (mask >= 10);
for (int i = 0; i < message.Length; i++)
{
if (message[i]%mask==0)
{
newMask= mask+message[i];
nonRevercedMsg += (char)newMask;
}
else
{
newMask = message[i]-mask;
nonRevercedMsg += (char)newMask;
}
newMask = 0;
}
char[] reversedMsg = nonRevercedMsg.ToCharArray();
Array.Reverse(reversedMsg);
foreach (var cryptedMsg in reversedMsg)
{
Console.Write(cryptedMsg);
}
Console.WriteLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment