using System.Collections.Generic;
public static string EncodeDecode(string text, bool decode = false)
var baconDict = new Dictionary<char, string>
{'a', "uuuuu"}, {'b', "uuuul"}, {'c', "uuulu"}, {'d', "uuull"}, {'e', "uuluu"},
{'f', "uulul"}, {'g', "uullu"}, {'h', "uulll"}, {'i', "uluuu"}, {'j', "uluul"},
{'k', "ululu"}, {'l', "ulull"}, {'m', "ulluu"}, {'n', "ullul"}, {'o', "ulllu"},
{'p', "ullll"}, {'q', "luuuu"}, {'r', "luuul"}, {'s', "luulu"}, {'t', "luull"},
{'u', "luluu"}, {'v', "lulul"}, {'w', "lullu"}, {'x', "lulll"}, {'y', "lluuu"},
{'z', "lluul"}, {' ', "lllll"}
var reverseBaconDict = new Dictionary<string, char>();
foreach (var kvp in baconDict)
reverseBaconDict[kvp.Value] = kvp.Key;
text = text.Replace(" ", "");
for (int i = 0; i < text.Length; i += 5)
string chunk = text.Substring(i, 5);
if (reverseBaconDict.ContainsKey(chunk))
decodedText += reverseBaconDict[chunk];
return "Invalid encoded text";
if (baconDict.ContainsKey(c))
encodedText += baconDict[c] + " ";
return encodedText.Trim();
public static void Main()
Console.WriteLine("What would you like to encode using the Baconian Cipher?");
string textToEncode = Console.ReadLine();
string encodedText = EncodeDecode(textToEncode);
Console.WriteLine($"Encoded: {encodedText}");