본문 바로가기

디지털포렌식(Digital forensic)/알파벳

[파일] 생존 신호 모스 부호, 이진화

반응형

모스 부호를 이진법으로 변환하는 방법은 간단하다.
모스 부호는 대시(-)와 점(.)으로 이루어진 부호체계이므로,
이진법으로 변환하려면 
대시(-)를 111로, 점(.)을 1로 
신호의 간격을 0, 글자 간격을 000, 단어 간격을 0000000로 규정한다.

 

만약, KOREA를 모스로 변환하면 아래와 같다.

 

K ::  -.- (이진법으로 변환하면 111010111)

O :: --- (이진법으로 변환하면 11101110111)

R :: . - . (이진법으로 변환하면 1011101)

E :: . (이진법으로 변환하면 1)

A :: . - (이진법으로 변환하면 10111)

 

KOREA는 111010111 000 11101110111 000 1011101 000 1 000 10111
으로 표현할 수 있다.

모스부호 이진화 소스 다운로드 ▼ 

 

ConsoleApp1.zip
0.03MB

 

using System;
using System.Collections.Generic;
using System.Text;

class MorseCodeConverter
{
    static Dictionary<char, string> morseCodeDict = new Dictionary<char, string>()
    {
        {'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', "--.."}
    };

    static string ToBinaryMorse(string input)
    {
        StringBuilder binaryMorse = new StringBuilder();
        foreach (char c in input)
        {
            if (c == ' ')
            {
                binaryMorse.Append(" 000 "); // 단어 간격
            }
            else if (morseCodeDict.ContainsKey(char.ToUpper(c)))
            {
                string morseCode = morseCodeDict[char.ToUpper(c)];
                foreach (char symbol in morseCode)
                {
                    if (symbol == '-')
                    {
                        binaryMorse.Append("1110"); // 대시
                    }
                    else if (symbol == '.')
                    {
                        binaryMorse.Append("10"); // 점
                    }
                }
                binaryMorse.Append("00 "); // 글자 간격
            }
        }
        return binaryMorse.ToString().Trim();
    }

    static void Main(string[] args)
    {
        string input = "KOREA";
        string binaryMorse = ToBinaryMorse(input);
        Console.WriteLine($"{input}를 이진 모스 부호로 변환하면: {binaryMorse}");
    }
}

실행결과

몇가지 단어를 입력한 후 결과를 확인해보면.

RUSSIA ::  1011101000 1010111000 10101000 10101000 101000 10111000
CHINA ::     11101011101000 1010101000 101000 11101000 10111000
ANSAN ::    10111000 11101000 10101000 10111000 11101000
WINE ::       101110111000 101000 11101000 1000

728x90