Advertisement
Guest User

encrypt

a guest
Aug 29th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Encrypt
  5. {
  6.     class Encrypt
  7.     {
  8.         private static void Main(string[] args)
  9.         {
  10.  
  11.             List<string> cryptomsg = new List<string>();
  12.  
  13.             string command = Console.ReadLine();
  14.  
  15.             while (command.ToLower() != "start")
  16.             {
  17.                 command = Console.ReadLine();
  18.             }
  19.  
  20.             int messages = 0;
  21.             command = Console.ReadLine();
  22.  
  23.             while (command.ToLower() != "end")
  24.             {
  25.                 if (command == string.Empty)
  26.                 {
  27.                     command = Console.ReadLine();
  28.                     continue;
  29.                 }
  30.  
  31.                 messages++;
  32.  
  33.                 string currentMessage = command;
  34.                 string result = string.Empty;
  35.  
  36.                 for (int i = 0; i < currentMessage.Length; i++)
  37.                 {
  38.                     char currentSymbol = currentMessage[i];
  39.  
  40.                     if (currentSymbol >= '0' && currentSymbol <= '9')
  41.                     {
  42.                         result = currentSymbol + result;
  43.                         continue;
  44.                     }
  45.  
  46.                     if (currentSymbol >= 'A')
  47.                     {
  48.                         if (currentSymbol <= 'M' || (currentSymbol >= 'a' && currentSymbol <= 'm'))
  49.                         {
  50.                             currentSymbol = (char) (currentSymbol + 13);
  51.                         }
  52.  
  53.                         else
  54.                         {
  55.                             currentSymbol = (char) (currentSymbol - 13);
  56.                         }
  57.                     }
  58.  
  59.                     else
  60.                     {
  61.                         switch (currentSymbol)
  62.                         {
  63.                             case ' ':
  64.                                 currentSymbol = '+';
  65.                                 break;
  66.                             case ',':
  67.                                 currentSymbol = '%';
  68.                                 break;
  69.                             case '.':
  70.                                 currentSymbol = '&';
  71.                                 break;
  72.                             case '?':
  73.                                 currentSymbol = '#';
  74.                                 break;
  75.                             case '!':
  76.                                 currentSymbol = '$';
  77.                                 break;
  78.                             case '+':
  79.                                 currentSymbol = ' ';
  80.                                 break;
  81.                             case '%':
  82.                                 currentSymbol = ',';
  83.                                 break;
  84.                             case '&':
  85.                                 currentSymbol = '.';
  86.                                 break;
  87.                             case '#':
  88.                                 currentSymbol = '?';
  89.                                 break;
  90.                             case '$':
  91.                                 currentSymbol = '!';
  92.                                 break;
  93.                         }
  94.                     }
  95.  
  96.                     result = currentSymbol + result;
  97.                 }
  98.  
  99.                 cryptomsg.Add(result);
  100.                 command = Console.ReadLine();
  101.             }
  102.  
  103.             if (messages == 0)
  104.             {
  105.                 Console.WriteLine("No messages sent.");
  106.             }
  107.  
  108.             else
  109.             {
  110.                 Console.WriteLine("Total number of messages: {0}", messages);
  111.  
  112.                 foreach (var msg in cryptomsg)
  113.                 {
  114.                     Console.WriteLine(msg);
  115.                 }
  116.             }
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement