Advertisement
Guest User

Untitled

a guest
May 1st, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.65 KB | None | 0 0
  1. using System;
  2.  
  3. class Encryptt
  4. {
  5.     private static void Main()
  6.     {
  7.         string command = Console.ReadLine();
  8.         string input;
  9.         string[] msg = new string[100];
  10.         int counter = 0;
  11.         int a = 0;
  12.  
  13.         while (msg[counter] != "END" && msg[counter] != "end")
  14.         {
  15.             if (command != "START" && command != "start")
  16.             {
  17.                 break;
  18.             }
  19.             else if (command == "START" || command == "start")
  20.             {
  21.                 a++;
  22.                 counter++;
  23.                 input = Console.ReadLine(); // take a string example "abcd"
  24.                 char[] msg1 = input.ToCharArray(); // example "[0]a, [1]b, [2]c, [3]d" type CHAR
  25.  
  26.                 if (input != "END" && input != "end")
  27.                 {
  28.  
  29.                     for (int i = 0; i < msg1.Length; i++)
  30.                     {
  31.  
  32.                         if (msg1[i] >= 'a' && msg1[i] <= 'm')
  33.                         {
  34.                             msg1[i] = (char)(msg1[i] + 13);
  35.                         }
  36.                         else if (msg1[i] >= 'n' && msg1[i] <= 'z')
  37.                         {
  38.                             msg1[i] = (char)(msg1[i] - 13);
  39.                         }
  40.                         else if (msg1[i] >= 'A' && msg1[i] <= 'M')
  41.                         {
  42.                             msg1[i] = (char)(msg1[i] + 13);
  43.                         }
  44.                         else if (msg1[i] >= 'N' && msg1[i] <= 'Z')
  45.                         {
  46.                             msg1[i] = (char)(msg1[i] - 13);
  47.                         }
  48.  
  49.  
  50.                         if (msg1[i] == ' ')
  51.                         {
  52.                             msg1[i] = '+';
  53.                         }
  54.                         else if (msg1[i] == ',')
  55.                         {
  56.                             msg1[i] = '%';
  57.                         }
  58.                         else if (msg1[i] == '.')
  59.                         {
  60.                             msg1[i] = '&';
  61.                         }
  62.                         else if (msg1[i] == '?')
  63.                         {
  64.                             msg1[i] = '#';
  65.                         }
  66.                         else if (msg1[i] == '!')
  67.                         {
  68.                             msg1[i] = '$';
  69.                         }
  70.  
  71.  
  72.  
  73.                         else if (msg1[i] == '+')
  74.                         {
  75.                             msg1[i] = ' ';
  76.                         }
  77.                         else if (msg1[i] == '%')
  78.                         {
  79.                             msg1[i] = ',';
  80.                         }
  81.                         else if (msg1[i] == '&')
  82.                         {
  83.                             msg1[i] = '.';
  84.                         }
  85.                         else if (msg1[i] == '#')
  86.                         {
  87.                             msg1[i] = '?';
  88.                         }
  89.                         else if (msg1[i] == '$')
  90.                         {
  91.                             msg1[i] = '!';
  92.                         }
  93.  
  94.                     }
  95.  
  96.                     Array.Reverse(msg1);
  97.  
  98.                 }
  99.                
  100.                 string m = new string(msg1); // example "[0]a, [1]b, [2]c, [3]d" type CHAR turns into "abcd" type STRING
  101.                 msg[counter] = m; // --||--
  102.  
  103.                 if ((string.IsNullOrEmpty(msg[counter])))
  104.                 {
  105.                     a--;
  106.                 }
  107.             }
  108.         }
  109.  
  110.        
  111.  
  112.        
  113.             int count = 0;
  114.             int count1 = 0;
  115.  
  116.             for (int i = 0; i < msg.Length; i++)
  117.             {
  118.                 if ((string.IsNullOrEmpty(msg[i])))
  119.                 {
  120.                     count1++;
  121.                 }
  122.                 else
  123.                 {
  124.                     if (msg[i] != "END" && msg[i] != "end")
  125.                     {
  126.                         count++;
  127.                     }
  128.                 }
  129.                
  130.             }
  131.  
  132.             if (count1 + 1 == 100)
  133.             {
  134.                 Console.WriteLine("No messages sent.");
  135.             }
  136.             else
  137.             {
  138.                 Console.WriteLine("Total number of messages: {0}", count);
  139.             }
  140.  
  141.             for (int i = 0; i < msg.Length; i++)
  142.             {
  143.  
  144.                 if ((string.IsNullOrEmpty(msg[i])))
  145.                 {
  146.                    
  147.                 }
  148.                 else
  149.                 {
  150.                     if(msg[i] != "END" && msg[i] != "end")
  151.                     {
  152.                         Console.WriteLine(msg[i]);
  153.                     }
  154.                  
  155.                 }
  156.                
  157.             }
  158.            
  159.         }
  160.  
  161.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement