-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
MorseEncoder.cs
40 lines (33 loc) · 889 Bytes
/
MorseEncoder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
namespace RonSijm.ButtFish.Encoders;
public class MorseEncoder : ICharacterEncoder
{
public string EncodeCharacter(char input)
{
var validInput = MorseAlphabetDictionary.TryGetValue(input, out var result);
if (!validInput)
{
Console.WriteLine($"Invalid input: '{input}' - Use a~h or 1~8", Color.Red);
}
return result;
}
private static readonly Dictionary<char, string> MorseAlphabetDictionary = new()
{
{'a', ".-"},
{'b', "-..."},
{'c', "-.-."},
{'d', "-.."},
{'e', "."},
{'f', "..-."},
{'g', "--."},
{'h', "...."},
{'1', ".----"},
{'2', "..---"},
{'3', "...--"},
{'4', "....-"},
{'5', "....."},
{'6', "-...."},
{'7', "--..."},
{'8', "---.."},
{' ', " "},
};
}