Tags: programming 

Rating: 5.0

```python
import pwn
import time

base_piano = [
'____________________________',
'| | | | | | | | | | | | ',
'| | | | | | | | | | | | ',
'| |1| |2| | |3| |4| |5| ',
'| |_| |_| | |_| |_| |_| ',
'| | | | | | | ',
'| C | D | E | F | G | A | B ',
'|___|___|___|___|___|___|___',
]

empty_piano = [
'____________________________',
'| | | | | | | | | | | | ',
'| | | | | | | | | | | | ',
'| | | | | | | | | | | | ',
'| |_| |_| | |_| |_| |_| ',
'| | | | | | | ',
'| | | | | | | ',
'|___|___|___|___|___|___|___'
]

end_line = [
'_',
'|',
'|',
'|',
'|',
'|',
'|',
'|',
]

note_mapping = {
'C': 'C',
'D': 'D',
'E': 'E',
'F': 'F',
'G': 'G',
'A': 'A',
'B': 'B',
'C#': '1',
'D#': '2',
'F#': '3',
'G#': '4',
'A#': '5',
'Db': '1',
'Eb': '2',
'Gb': '3',
'Ab': '4',
'Bb': '5'
}

piano_characters = 'ABCDEFG12345'

def piano_from_note(piano, note):
new_piano = []
for line in piano:
new_piano.append(line.replace(note_mapping[note], 'X'))
return new_piano

def clean_piano(piano):
cleaned_piano = []
for line in piano:
new_line = line
for char in piano_characters:
new_line = new_line.replace(char, ' ')
cleaned_piano.append(new_line)
return cleaned_piano

def note_from_request(request):
split_request = request.split()
counter = split_request[3].replace('th', '').replace('st', '').replace('nd', '').replace('rd', '')
note = split_request[4]
return (counter, note)

def assemble_zipped_piano(zipped_piano):
lines = []
for tup in zipped_piano:
joined = ''.join(tup)
lines.append(f'{joined}\n')
return ''.join(lines)

def build_output(query):
counter, note = note_from_request(query)
solved_base_piano = piano_from_note(base_piano, note)
cleaned_solved_base_piano = clean_piano(solved_base_piano)
zipped_piano = zip(*[empty_piano for c in range(0, int(counter)-1)], cleaned_solved_base_piano, end_line)
return assemble_zipped_piano(zipped_piano)

def main():
host = 'prog.dvc.tf'
port = 7751
conn = pwn.remote(host, port)
for i in range(0, 12):
start_stuff = conn.recvline()
query = conn.recvline()
time.sleep(1)
output = build_output(query.decode('utf-8'))
conn.send(bytes(output, 'utf-8'))
while True:
line = conn.recvline()
print(line.decode('utf-8'))

main()
```