-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_19.py
39 lines (31 loc) · 1.1 KB
/
level_19.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
#!/bin/env python
# coding=utf-8
# http://butter:fly@www.pythonchallenge.com/pc/hex/bin.html
# Indian? Endian!
# @see http://www.lightlink.com/tjweber/StripWav/Canon.html
import email
import re
from array import array
import requests
PREFIX = "http://butter:fly@www.pythonchallenge.com/pc/hex/"
url = PREFIX + 'bin.html'
def catch(text, pattern=r'<!--(.*?)-->', cnt=0):
return re.findall(pattern, text, re.DOTALL)[cnt]
def solve(something):
msg = email.message_from_string(something.strip())
attachment = msg.get_payload()[0]
fname = attachment.get_filename()
audio = attachment.get_payload(decode=True)
header = audio[:44] # copy wav-header
a = array('H', audio[44:])
a.byteswap()
with open(fname, 'wb') as file:
file.write(header)
a.tofile(file)
# Generate "indian.wav" in current folder
if __name__ == "__main__":
r = requests.get(url)
something = catch(r.text)
answer = solve(something)
# You are an idiot ha ha ha ha ah ha ha haha ha haha.
# http://butter:fly@www.pythonchallenge.com/pc/hex/idiot.html