-
Notifications
You must be signed in to change notification settings - Fork 1
/
solution.py
executable file
·59 lines (43 loc) · 1.66 KB
/
solution.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
#!/usr/bin/env python3
import pyshark
DELAY_THRESHOLD = 0.5
cap = pyshark.FileCapture('../challenge/patience.pcap', use_json=True)
stream_count = {}
i = 0
morse_code = ''
MORSE_CODE_DICT = {'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': '-----', ', ': '--..--', '.': '.-.-.-',
'?': '..--..', '/': '-..-.', '-': '-....-',
'(': '-.--.', ')': '-.--.-',
' ': ""}
REVERSE_MORSE_CODE_DICT = {}
for character in MORSE_CODE_DICT:
code = MORSE_CODE_DICT[character]
REVERSE_MORSE_CODE_DICT[code] = character
for pkt in cap:
if 'HTTP' in pkt:
# print(pkt['HTTP'])
if 'time' in str(pkt['HTTP']):
response_time = float(pkt['HTTP'].time)
if response_time > 2*DELAY_THRESHOLD:
morse_code += ' '
elif response_time > DELAY_THRESHOLD:
morse_code += '-'
else:
morse_code += '.'
print(morse_code)
flag = ''
for code in morse_code.split(' '):
flag += REVERSE_MORSE_CODE_DICT[code]
print(flag)