repl.it
@jacksoncds/

ItchyUnpleasantPrinter

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;

class MainClass {
  public static void Main (string[] args) {
    var caesarCipher = new CaesarCipher();

    caesarCipher.Encrypt(3, "attack from the woods at dawn");
  }
}

public class CaesarCipher {
  public void Encrypt(int key, string text){
    
    if(key < 1 || key > 26){
      throw new Exception("Key must be between 1 and 26 inclusive.");
    }

    Console.WriteLine("Plain:");
    Console.WriteLine(text);

    var decText = new char[text.Length];

    for(int i = 0; i < text.Length; i++){
      int dec = (int)text[i];

      if(dec >= 65 && dec <= 90 || dec >= 97 && dec <= 122){
        decText[i] = (char)(dec + key);
      } else {
        decText[i] = (char)dec;
      }
    }

    Console.WriteLine("Encrypted:");
    Console.WriteLine(decText);
  }
}
Fetching token
?