diff --git a/src/Program.cs b/src/Program.cs new file mode 100644 index 0000000..5f83b6c --- /dev/null +++ b/src/Program.cs @@ -0,0 +1,140 @@ +using System.Text; + +namespace scream +{ + /// + /// Implements the Scream Cipher, encoding messages using diacritics on the letter 'A'. + /// + class Program + { + /// + /// The base character 'A' used for encoding messages with diacritics. + /// + private const char BASE_CHARACTER = 'A'; + + /// + /// The starting ASCII value of printable characters. + /// + private const int ASCII_START = 0x20; + + /// + /// The ending ASCII value of printable characters. + /// + /// + /// Not used, but included for reference + /// + private const int ASCII_END = 0x7E; + + /// + /// The starting Unicode code point for diacritic marks. + /// + private const int DIACRITIC_START = 0x300; + + /// + /// The ending Unicode code point for diacritic marks. + /// + /// + /// Not used, but included for reference + /// + private const int DIACRITIC_END = 0x36F; // Not needed, but here for reference. + + /// Main entry-point for this application. + /// The component parts of the message. + static void Main(string[] args) + { + if (args[0].Equals("-q") || args[0].Equals("--quiet")) + { + QuietDown(args); + } + else if (args.Length > 0) + { + var scream = Scream(args); + Console.OutputEncoding = System.Text.Encoding.UTF8; + Console.WriteLine(scream); + } + else + { + return; + } + } + + /// Quiets the given message as defined by the string arry. + /// The component parts of the message. + /// A string representing the quiet message. + private static string QuietDown(string[] messageComponents) + { + var concat = string.Concat(messageComponents.Skip(1)); + StringBuilder sb = new StringBuilder(); + + foreach (var c in concat) + { + var index = GetAsciiIndex(c); + var ascii = GetAscii(index); + + sb.Append(ascii); + } + + return sb.ToString(); + } + + /// Screams the given message as defined by the string array. + /// The component parts of the message. + /// A string representing the screamed message. + private static string Scream(string[] messageComponents) + { + var concat = string.Concat(messageComponents); + StringBuilder sb = new StringBuilder(); + + foreach (var c in concat) + { + var index = GetDiacriticIndex(c); + var diacritic = GetDiacritic(index); + + sb.Append(BASE_CHARACTER); + sb.Append(diacritic); + } + + return sb.ToString(); + } + + /// Gets the zero-based index of the diacritic character. + /// The diacritic character to index. + /// The diacritic character index. + private static int GetDiacriticIndex(char character) + { + var index = character - ASCII_START; + + return index; + } + + /// Gets the zero-based index of the viewable ASCII character. + /// The ASCII character to index. + /// The ASCII character index. + private static int GetAsciiIndex(char character) + { + var index = character - DIACRITIC_START; + + return index; + } + + /// Gets a diacritic character given an index offset. + /// Zero-based index of the Diacritic character. + /// The diacritic character. + private static char GetDiacritic(int index) + { + var diacritic = (char)(DIACRITIC_START + index); + + return diacritic; + } + + /// Gets an ASCII character given an index offset. + /// Zero-based index of the ASCII character. + /// The ASCII character. + private static char GetAscii(int index) + { + var character = (char)(ASCII_START + index); + + return character; + } + } +} \ No newline at end of file diff --git a/src/Properties/launchSettings.json b/src/Properties/launchSettings.json new file mode 100644 index 0000000..c521ae9 --- /dev/null +++ b/src/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "scream": { + "commandName": "Project", + "commandLineArgs": "Commit of the code." + } + } +} \ No newline at end of file diff --git a/src/scream.csproj b/src/scream.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/src/scream.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/src/scream.sln b/src/scream.sln new file mode 100644 index 0000000..bd66cc7 --- /dev/null +++ b/src/scream.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35707.178 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "scream", "scream.csproj", "{356B3F61-4A5F-49D8-8389-5B99516275C0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {356B3F61-4A5F-49D8-8389-5B99516275C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {356B3F61-4A5F-49D8-8389-5B99516275C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {356B3F61-4A5F-49D8-8389-5B99516275C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {356B3F61-4A5F-49D8-8389-5B99516275C0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal