(char TextChar, string MorseCode)[] _morseCode = new[]
{
('A', ".-"), ('B', "-..."), ('C', "-.-."), ('D', "-.."), ('E', "."), ('F', "..-."),
('G', "--."), ('H', "...."), ('I', ".."), ('J', ".---"), ('K', "-.-"), ('L', ".-.."),
('M', "--"), ('N', "-."), ('O', "---"), ('P', ".--."), ('Q', "--.-"), ('R', ".-."),
('S', "..."), ('T', "-"), ('U', "..-"), ('V', "...-"), ('W', ".--"), ('X', "-..-"),
('Y', "-.--"), ('Z', "--.."), ('0', "-----"), ('1', ".----"), ('2', "..---"), ('3', "...--"),
('4', "....-"), ('5', "....."), ('6', "-...."), ('7', "--..."), ('8', "---.."), ('9', "----."),
('.', ".-.-.-"), (',', "--..--"), ('?', "..--.."), ('\'', ".----."), ('!', "-.-.--"), ('/', "-..-."),
('(', "-.--."), (')', "-.--.-"), ('&', ".-..."), (':', "---..."), (';', "-.-.-."), ('=', "-...-"),
('+', ".-.-."), ('-', "-....-"), ('_', "..--.-"), ('\"', ".-..-."), ('$', "...-..-"), ('@', ".--.-."),
(' ', "/")
};
public string Decode(string input)
{
var morseCodeToChar = _morseCode.ToDictionary(_ => _.MorseCode, _ => _.TextChar);
var decoded = input.Split(' ').Select(morseCodeToChar.GetValueOrDefault);
return string.Concat(decoded);
}
public string Encode(string morseInput)
{
var charToMorseCode = _morseCode.ToDictionary(_ => _.TextChar, _ => _.MorseCode);
var decoded = morseInput.Select(c => charToMorseCode.GetValueOrDefault(char.ToUpper(c)));
return string.Join(" ", decoded);
}
(char TextChar, string MorseCode)[] _morseCode = new[]
{
('A', ".-"), ('B', "-..."), ('C', "-.-."), ('D', "-.."), ('E', "."), ('F', "..-."),
('G', "--."), ('H', "...."), ('I', ".."), ('J', ".---"), ('K', "-.-"), ('L', ".-.."),
('M', "--"), ('N', "-."), ('O', "---"), ('P', ".--."), ('Q', "--.-"), ('R', ".-."),
('S', "..."), ('T', "-"), ('U', "..-"), ('V', "...-"), ('W', ".--"), ('X', "-..-"),
('Y', "-.--"), ('Z', "--.."), ('0', "-----"), ('1', ".----"), ('2', "..---"), ('3', "...--"),
('4', "....-"), ('5', "....."), ('6', "-...."), ('7', "--..."), ('8', "---.."), ('9', "----."),
('.', ".-.-.-"), (',', "--..--"), ('?', "..--.."), ('\'', ".----."), ('!', "-.-.--"), ('/', "-..-."),
('(', "-.--."), (')', "-.--.-"), ('&', ".-..."), (':', "---..."), (';', "-.-.-."), ('=', "-...-"),
('+', ".-.-."), ('-', "-....-"), ('_', "..--.-"), ('\"', ".-..-."), ('$', "...-..-"), ('@', ".--.-."),
(' ', "/")
};
public string Decode(string input)
{
var morseCodeToChar = _morseCode.ToDictionary(_ => _.MorseCode, _ => _.TextChar);
var decoded = input.Split(' ').Select(morseCodeToChar.GetValueOrDefault);
return string.Concat(decoded);
}
public string Encode(string morseInput)
{
var charToMorseCode = _morseCode.ToDictionary(_ => _.TextChar, _ => _.MorseCode);
var decoded = morseInput.Select(c => charToMorseCode.GetValueOrDefault(char.ToUpper(c)));
return string.Join(" ", decoded);
}