// C# program for the above approach
using System;
using System.Collections.Generic;
class AtbashCipher {
// Map to lookup various alphabets
static Dictionary<char, char> lookup_table
= new Dictionary<char, char>{
{ 'A', 'Z' }, { 'B', 'Y' }, { 'C', 'X' },
{ 'D', 'W' }, { 'E', 'V' }, { 'F', 'U' },
{ 'G', 'T' }, { 'H', 'S' }, { 'I', 'R' },
{ 'J', 'Q' }, { 'K', 'P' }, { 'L', 'O' },
{ 'M', 'N' }, { 'N', 'M' }, { 'O', 'L' },
{ 'P', 'K' }, { 'Q', 'J' }, { 'R', 'I' },
{ 'S', 'H' }, { 'T', 'G' }, { 'U', 'F' },
{ 'V', 'E' }, { 'W', 'D' }, { 'X', 'C' },
{ 'Y', 'B' }, { 'Z', 'A' }
};
// Function to implement Atbash Cipher
static string Atbash(string message)
{
string cipher = "";
foreach(char letter in message)
{
// Checking for space
if (letter != ' ') {
// Adds the corresponding letter from the
// lookup_table
cipher
+= lookup_table[Char.ToUpper(letter)];
}
else {
// Adds space
cipher += ' ';
}
}
return cipher;
}
// Driver function to run the program
static void Main()
{
// Encrypt the given message
string message = "GEEKS FOR GEEKS";
Console.WriteLine(Atbash(message));
// Decrypt the given message
message = "TVVPH ULI TVVPH";
Console.WriteLine(Atbash(message));
}
}
// This code is contributed by princekumaras