public static void Main()
string key = "helloworld";
string input = "thisisasecretmessage";
string encrypted = VigenereCipher.Encipher(input, key);
Console.WriteLine(encrypted);
string decrypted = VigenereCipher.Decipher(encrypted, key);
Console.WriteLine(decrypted);
public class VigenereCipher
public static string Encipher(string input, string key)
string output = string.Empty;
for (int i = 0, j = 0; i < input.Length; i++)
if (c < 'A' || c > 'Z' && c < 'a' || c > 'z')
output += (char)((c & 96) + (c - 'A' + key[j] - 'A') % 26);
public static string Decipher(string input, string key)
string output = string.Empty;
for (int i = 0, j = 0; i < input.Length; i++)
if (c < 'A' || c > 'Z' && c < 'a' || c > 'z')
output += (char)((c & 96) + (c - 'A' - (key[j] - 'A') + 26) % 26);