Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace EncryptTheMessages
- {
- class EncryptTheMessages
- {
- static void Main()
- {
- int numberOfMsg = 0;
- string result = "";
- string start = Console.ReadLine();
- while (start != "START" && start != "start")
- {
- start = Console.ReadLine();
- }
- string input = Console.ReadLine();
- while (input != "END" && input != "end")
- {
- if (string.IsNullOrWhiteSpace(input))
- {
- input = Console.ReadLine();
- continue;
- }
- result += EncryptedWord(input);
- result += Environment.NewLine;
- input = Console.ReadLine();
- if (input == "End" && input == "end")
- {
- break;
- }
- numberOfMsg += Message(0);
- }
- if (numberOfMsg != 0)
- {
- Console.WriteLine("Total number of messages: {0}",numberOfMsg);
- Console.WriteLine(result);
- }
- else
- {
- Console.WriteLine("No messages sent.");
- }
- }
- static private string EncryptedWord(string word)
- {
- string encryptedMsg = "";
- int charDifference = 13;
- for (int i = word.Length - 1; i >= 0; i--)
- {
- if (char.IsLetter(word[i]))
- {
- if ((word[i] >= 'A' && word[i] <= 'M') || (word[i] >= 'a' && word[i] <= 'm'))
- {
- int swap = Convert.ToInt32(word[i]) + charDifference;
- encryptedMsg += Convert.ToChar(swap);
- }
- else if ((word[i] >= 'N' && word[i] <= 'Z') || (word[i] >= 'n' && word[i] <= 'z'))
- {
- int swap = Convert.ToInt32(word[i]) - charDifference;
- encryptedMsg += Convert.ToChar(swap);
- }
- }
- else
- {
- switch (word[i])
- {
- case ' ': encryptedMsg += '+'; break;
- case ',': encryptedMsg += '%'; break;
- case '.': encryptedMsg += '&'; break;
- case '?': encryptedMsg += '#'; break;
- case '!': encryptedMsg += '$'; break;
- default: encryptedMsg += word[i]; break;
- }
- }
- }
- if (!(string.IsNullOrEmpty(encryptedMsg)))
- {
- Message(0);
- }
- return encryptedMsg;
- }
- static private int Message(int msg)
- {
- msg++;
- return msg;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment