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 EncryptedMatrix
- {
- class EncryptedMatrix
- {
- static void Main()
- {
- string message = Console.ReadLine();
- string direction = Console.ReadLine();
- string convertedMessage = "0";
- foreach (char ch in message.ToCharArray())
- {
- int lastDigit = ch % 10;
- convertedMessage += lastDigit;
- }
- convertedMessage += "0";
- string encryptedMessage = "";
- for (int i = 1; i < convertedMessage.Length - 1; i++)
- {
- int digit = convertedMessage[i] - '0';
- if (digit % 2 == 0)
- {
- encryptedMessage += digit * digit;
- }
- else
- {
- encryptedMessage += digit + convertedMessage[i - 1] - '0' + convertedMessage[i + 1] - '0';
- }
- }
- int len = encryptedMessage.Length;
- int[,] matrix = new int[len, len];
- if (direction == "\\")
- {
- for (int i = 0; i < len; i++)
- {
- matrix[i, i] = encryptedMessage[i] - '0';
- }
- }
- else
- {
- for (int i = 0; i < len; i++)
- {
- matrix[len - 1 - i, i] = encryptedMessage[i] - '0';
- }
- }
- for (int i = 0; i < len; i++)
- {
- for (int j = 0; j < len; j++)
- {
- Console.Write(matrix[i,j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement