public class SubstitutionCipher
public static void Main()
Console.Write("Enter your key, use just natural nums:");
string key = Convert.ToString(Console.ReadLine());
char[] justNums = new char[key.Length];
for(int a = 0; a<key.Length; a++)
if((key[a]=='0')||(key[a]=='1')||(key[a]=='2')||(key[a]=='3')||(key[a]=='4')||(key[a]=='5')||(key [a]=='6')||(key[a]=='7')||(key[a]=='8')||(key[a]=='9'))
Console.WriteLine("You enter in your key natural nums :)");
Console.WriteLine("You did not enter in your key natural nums this wont work, start again and enter natural nums!!");
Console.Write("Enter 1 if you want to encrypt and if you want to decrypt enter any number except 1:");
int youWantTo = int.Parse(Console.ReadLine());
Console.Write("Enter a sentence:");
string plainText = Convert.ToString(Console.ReadLine());
string cipherText = Encrypt(plainText, key);
string decryptedText = Decrypt(cipherText, key);
Console.WriteLine("Plain : {0}", plainText);
Console.WriteLine("Encrypted : {0}", cipherText);
Console.Write("Enter a sentence:");
string cipherText = Convert.ToString(Console.ReadLine());
string decryptedText = Decrypt(cipherText, key);
Console.WriteLine("Encrypted : {0}", cipherText);
Console.WriteLine("Decrypted : {0}", decryptedText);
static string Encrypt(string plainText, string key)
char[] chars = new char[plainText.Length];
for(int i = 0; i < plainText.Length; i++)
char[] justNums = new char[key.Length];
for(int a = 0; a<key.Length; a++)
chars[i]= Convert.ToChar((plainText[i])+ g);
return new string(chars);
static string Decrypt(string cipherText, string key)
char[] chars = new char[cipherText.Length];
for(int i = 0; i < cipherText.Length; i++)
if (cipherText[i] == ' ')
char[] justNums = new char[key.Length];
for(int a = 0; a<key.Length; a++)
chars[i]= Convert.ToChar((cipherText[i])-g);
return new string(chars);