ẠA͏A͍A͍A͉A͔A͏A͆A͔A͈AͅA̓A͏Ä́AͅA̎
This commit is contained in:
parent
0deca186ff
commit
44d32cf4fb
4 changed files with 180 additions and 0 deletions
140
src/Program.cs
Normal file
140
src/Program.cs
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace scream
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implements the Scream Cipher, encoding messages using diacritics on the letter 'A'.
|
||||||
|
/// </summary>
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The base character 'A' used for encoding messages with diacritics.
|
||||||
|
/// </summary>
|
||||||
|
private const char BASE_CHARACTER = 'A';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The starting ASCII value of printable characters.
|
||||||
|
/// </summary>
|
||||||
|
private const int ASCII_START = 0x20;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ending ASCII value of printable characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Not used, but included for reference
|
||||||
|
/// </remarks>
|
||||||
|
private const int ASCII_END = 0x7E;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The starting Unicode code point for diacritic marks.
|
||||||
|
/// </summary>
|
||||||
|
private const int DIACRITIC_START = 0x300;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ending Unicode code point for diacritic marks.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Not used, but included for reference
|
||||||
|
/// </remarks>
|
||||||
|
private const int DIACRITIC_END = 0x36F; // Not needed, but here for reference.
|
||||||
|
|
||||||
|
/// <summary> Main entry-point for this application. </summary>
|
||||||
|
/// <param name="args"> The component parts of the message. </param>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Quiets the given message as defined by the string arry. </summary>
|
||||||
|
/// <param name="messageComponents"> The component parts of the message. </param>
|
||||||
|
/// <returns> A string representing the quiet message. </returns>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Screams the given message as defined by the string array. </summary>
|
||||||
|
/// <param name="messageComponents"> The component parts of the message. </param>
|
||||||
|
/// <returns> A string representing the screamed message. </returns>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets the zero-based index of the diacritic character. </summary>
|
||||||
|
/// <param name="character"> The diacritic character to index. </param>
|
||||||
|
/// <returns> The diacritic character index. </returns>
|
||||||
|
private static int GetDiacriticIndex(char character)
|
||||||
|
{
|
||||||
|
var index = character - ASCII_START;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets the zero-based index of the viewable ASCII character. </summary>
|
||||||
|
/// <param name="character"> The ASCII character to index. </param>
|
||||||
|
/// <returns> The ASCII character index. </returns>
|
||||||
|
private static int GetAsciiIndex(char character)
|
||||||
|
{
|
||||||
|
var index = character - DIACRITIC_START;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets a diacritic character given an index offset. </summary>
|
||||||
|
/// <param name="index"> Zero-based index of the Diacritic character. </param>
|
||||||
|
/// <returns> The diacritic character. </returns>
|
||||||
|
private static char GetDiacritic(int index)
|
||||||
|
{
|
||||||
|
var diacritic = (char)(DIACRITIC_START + index);
|
||||||
|
|
||||||
|
return diacritic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets an ASCII character given an index offset. </summary>
|
||||||
|
/// <param name="index"> Zero-based index of the ASCII character. </param>
|
||||||
|
/// <returns> The ASCII character. </returns>
|
||||||
|
private static char GetAscii(int index)
|
||||||
|
{
|
||||||
|
var character = (char)(ASCII_START + index);
|
||||||
|
|
||||||
|
return character;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
src/Properties/launchSettings.json
Normal file
8
src/Properties/launchSettings.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"scream": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "Commit of the code."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/scream.csproj
Normal file
10
src/scream.csproj
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
22
src/scream.sln
Normal file
22
src/scream.sln
Normal file
|
@ -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
|
Loading…
Reference in a new issue