Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Decrypter
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             String input = "-1";
  13.             while (input != "0")
  14.             {
  15.                 Console.WriteLine("Wat wil je doen?");
  16.                 Console.WriteLine("1: Iets Caesar decoderen");
  17.                 Console.WriteLine("0: Sluiten");
  18.                 input = Console.ReadLine();
  19.                 switch (input)
  20.                 {
  21.                     case "1":
  22.                         CaesarMenu();
  23.                         break;
  24.                     case "0":
  25.                         Console.WriteLine("We sluiten...");
  26.                         break;
  27.                     default:
  28.                         Console.WriteLine("Ken ik niet...");
  29.                         break;
  30.                 }
  31.             }
  32.  
  33.         }
  34.         static void CaesarMenu()
  35.         {
  36.             String input = "-1";
  37.             while (input != "0")
  38.             {
  39.                 Console.WriteLine("Geef de Caesar code in ofwel een 0 om te stoppen");
  40.                 input = Console.ReadLine();
  41.                 if (input != "0")
  42.                 {
  43.                     Console.WriteLine("Geef nu de C in");
  44.                     int C = 17;
  45.                     Console.WriteLine("De output is= " + DecypherCaesar(input, C));
  46.                 }
  47.             }
  48.         }
  49.         static String DecypherCaesar(String input, int C)
  50.         {
  51.             int strLen = input.Length;
  52.             String output="";
  53.             for (int i = 1; i <= strLen; i++)
  54.             {
  55.                 int asc = Convert.ToInt32(Convert.ToSByte(input[i - 1]));
  56.                 if(asc >= 65 && asc <= 90){
  57.                     asc = asc - C;
  58.                     if(asc < 65){
  59.                         if (asc == 64)
  60.                             asc = 32;
  61.                         else
  62.                             asc = asc + 27;
  63.                     }
  64.                 }
  65.  
  66.                 output+=char.ConvertFromUtf32(asc);
  67.             }
  68.             return output;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement