본문 바로가기

[Wargame Write-up]/HackThis!!

[HackThis!!] [CRYPT] LEVEL 3

Crypt 3번째 문제이다.


모스(morse) 부호로 된 문자열이 있다.




다음과 같이 모스 부호 복호화 코드를 짜 보자.


공백(' ')은 각 문자를 나누는 token, '/'는 단어 사이를 나누는 token이 된다.


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
 
morse_code = {
        '.-':    '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',        '.----':'1',        '..---':'2',        '...--':'3',        '....-':'4',
        '.....':'5',        '-....':'6',        '--...':'7',        '---..':'8',        '----.':'9',        '-----':'0',
        '--..--':',',       '---...':':',       '..--..':'?',       '.----.':"'",       '-....-':'-',       '-..-.':'/'
}
 
def decrypt_morse(morsecode, token1=None, token2=None):    
    result = ''
    for s in morsecode.split(token1):
        if s in morse_code.keys():
            result += morse_code[s]
        
        elif s == token2:
            result += ' '
 
    return result
 
def main():
    
    ciphertext = '.... .. --..-- / - .... .- -. -.- ... / - --- / ... .- -- ..- . .-.. / -- --- .-. ... . /'
    ciphertext += ' - .... . / - .-. .- -. ... -- .. ... ... .. --- -. / --- ..-. / - . .-.. . --. .-. .- .--. .... .. -.-. /'
    ciphertext += ' .. -. ..-. --- .-. -- .- - .. --- -. / .-- .- ... / ... - .- -. -.. .- .-. -.. .. --.. . -.. .-.-.- /'
    ciphertext += ' .... . / ..- ... . -.. / -.. --- - ... / .- -. -.. / -.. .- ... .... . ... / - --- / -.-. .-. . .- - . /'
    ciphertext += ' .- / ... - .- -. -.. .- .-. -.. / .-- .- -.-- / --- ..-. / -.-. --- -- -- ..- -. .. -.-. .- - .. --- -. --..-- /'
    ciphertext += ' .... . / .... .- ... / .... . .-.. .--. . -.. / -.-- --- ..- / - --- -.. .- -.-- / - --- / --. . - / - .... . /'
    ciphertext += ' .--. .- ... ... ---... / - .... .- -. -.- -.-- --- ..- ... .. .-.'
    
    print 'ciphertext: %s\n' % ciphertext
    print 'decrypted: %s' % decrypt_morse(ciphertext, ' ''/')
 
if __name__ == '__main__':
    main()
 
 
cs



실행하면 답이 나온다.


'[Wargame Write-up] > HackThis!!' 카테고리의 다른 글

[HackThis!!] [BASIC+] LEVEL 3  (0) 2016.12.25
[HackThis!!] [CRYPT] LEVEL 4  (0) 2016.12.22
[HackThis!!] [CRYPT] LEVEL 2  (0) 2016.12.22
[HackThis!!] [CRYPT] LEVEL 1  (0) 2016.12.21
[HackThis!!] [INTERMEDIATE] LEVEL 5  (0) 2016.12.19