Archived
Private
Public Access
1
0
This repository has been archived on 2026-02-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ProjectBackup/C#/Caesar Entschlüsseler/Program.cs
2022-09-04 12:45:01 +02:00

43 lines
1.1 KiB
C#

// See https://aka.ms/new-console-template for more information
using System;
using System.Collections.Generic;
List<char> alphabet = new (new[] {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z'
});
Console.WriteLine("Caesar Entschlüsseler");
Console.Write("Gebe die Nachricht ein: ");
string message = Console.ReadLine().ToLower();
char[] chars = message.ToCharArray();
while (true) {
Console.Clear();
Console.Write("Gebe den Token ein: ");
int token = Convert.ToInt32(Console.ReadLine());
string newMsg = "";
for (var i = 0; i < message.Length; i++) {
if (chars[i] == ' ') {
newMsg += " ";
continue;
}
int index = alphabet.FindIndex(ch => ch == chars[i]) + token;
if (index < 0)
index = alphabet.Count - index;
if (index >= alphabet.Count)
index = index - alphabet.Count;
newMsg += alphabet[index];
}
Console.WriteLine("Nachricht: " + newMsg.ToUpper());
Console.ReadKey();
}