Advertisement
Dianov

Data Types and Variables - More Exercise (05. Decrypting Message)

Aug 7th, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace DecryptingMessages
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int key = int.Parse(Console.ReadLine()); // receiving user's key
  11.             int n = int.Parse(Console.ReadLine()); // number of lines, which will follow
  12.             StringBuilder decryptedMessage = new StringBuilder();
  13.  
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 char userInput = char.Parse(Console.ReadLine());
  17.                 int asciiValue = key + (int)userInput;
  18.                 decryptedMessage.Append(Convert.ToChar(asciiValue));
  19.             }
  20.  
  21.             Console.WriteLine(decryptedMessage);
  22.         }
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement