-
-
Save codecademydev/212b66e0f6bd4bf1d4735dbae57226e3 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace CaesarCipher | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
char[] alphabet = new char[] {'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("Please, enter a message: "); | |
char[] secretMessage = Console.ReadLine().ToCharArray(); | |
char[] encryptedMessage = new char[secretMessage.Length]; | |
int index = 0; | |
foreach(char character in secretMessage) { | |
encryptedMessage[index ++] = alphabet.Contains(character) ? alphabet[(Array.IndexOf(alphabet, character) + 3) % alphabet.Length] : character; | |
} | |
Console.WriteLine(String.Join("", encryptedMessage)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment