-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaby_morse.py
65 lines (50 loc) · 1.7 KB
/
baby_morse.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
@author Corentin Goetghebeur (github.com/CorentinGoet)
Python script for the FCSC 2022 baby_morse challenge.
"""
from pwn import *
import numpy as np
# Connection parameters
HOST = "challenges.france-cybersecurity-challenge.fr"
PORT = 2250
alphabet = {'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': '-----', ', ': '--..--', '.': '.-.-.-',
'?': '..--..', '/': '-..-.', '-': '-....-',
'(': '-.--.', ')': '-.--.-'}
rev_alphabet = {v: k for k, v in alphabet.items()}
def morse_encode(msg: str):
"""
Encodes a message into morse code.
"""
cipher = []
for word in msg.split(' '):
for char in word:
cipher.append(alphabet.get(char))
cipher.append(' ')
cipher[-1] = ' '
return "".join(cipher).strip()
def main():
# Connect to the server
c = remote(HOST, PORT)
# Wait for the server to be ready
c.recvuntil(b'> ')
msg = "FLAG"
morse_msg = morse_encode(msg)
print(f"Message: {msg}, Morse encoded: {morse_msg}")
c.sendline(bytes(morse_msg, 'utf8'))
# Wait for server response
flag = str(c.recv(), 'utf8')
print(flag)
if __name__ == '__main__':
main()