NMDanny

Strings 1

Jan 16th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication21
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Would you like to encrypt or decrypt a string?");
  14.             string Choice = Console.ReadLine().ToLower();
  15.             if (Choice[0] == 'e')
  16.             {
  17.                 string Stnew = "";
  18.                 Console.WriteLine("Input a string");
  19.                 string St = Console.ReadLine().ToLower();
  20.  
  21.                 for (int i = 0; i < St.Length; ++i)
  22.                 {
  23.  
  24.                     if (St[i] != 'z')
  25.                     {
  26.                         Stnew += (char)(St[i] + 1);
  27.                     }
  28.                     else
  29.                     {
  30.                         Stnew += 'a';
  31.                     }
  32.                 }
  33.                 Console.WriteLine(Stnew);
  34.             }
  35.             else
  36.             {
  37.  
  38.                 string Stnew = "";
  39.                 Console.WriteLine("Input a string");
  40.                 string St = Console.ReadLine().ToLower();
  41.  
  42.                 for (int i = 0; i < St.Length; ++i)
  43.                 {
  44.  
  45.                     if (St[i] != 'a')
  46.                     {
  47.                         Stnew += (char)(St[i] - 1);
  48.                     }
  49.                     else
  50.                     {
  51.                         Stnew += 'z';
  52.                     }
  53.                 }
  54.                 Console.WriteLine(Stnew);
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment