Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 25, 2022 17:40
Show Gist options
  • Save codecademydev/212b66e0f6bd4bf1d4735dbae57226e3 to your computer and use it in GitHub Desktop.
Save codecademydev/212b66e0f6bd4bf1d4735dbae57226e3 to your computer and use it in GitHub Desktop.
Codecademy export
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