# 0x01 解法过程

• Hint1: 你们做音频题都不喜欢看时域图？
根据这个，用Cooledit看一下时域波形，如下：

image.png

``````[Python]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wave
import matplotlib.pyplot as plt
import numpy
import os

path = 'D:\PyCharm\Projects\CTF\Javis OJ\misc\god_wave\\'
wav = wave.open(path+'godwave.wav','rb')

params = wav.getparams()
nchannels, sampwidth, framerate, nframes = params[:4]

waveData = numpy.fromstring(strData, dtype=numpy.int16) #上述字符串转int
waveData = waveData*1.0/(max(abs(waveData))) #wave幅值归一化，与Cool edit的norm纵轴数值一致

#将音频转化为01串
string = ''
norm = 0
for i in range(1735680):
norm = norm+abs(waveData[i])
if (i+1) % 64 == 0:
if norm > 10:
string += '1'
else:
string += '0'
norm = 0

with open('01output.txt','w') as output:
output.writelines(string)
``````

• Hint2: 在数据传输过程中，我们往往会使用一种自带时钟的编码以减少误码率
搜索“自带时钟的编码”，说是曼彻斯特编码。写脚本把上面得到的01串做曼彻斯特解码，负电平为1，正电平 为0：
``````# -*- coding: utf-8 -*-
file_in = open('01output.txt','r')
file_in.close()
le = len(str(code))
print le
print code

result = ''
count = 0
res = 0
while code != '':
cp = code[:2]
if cp != '':
if cp[0] == '0' and cp[1] == '1':
res = (res<<1)|0
count +=1
if cp[0] == '1' and cp[1] == '0':
res = (res<<1)|1
count +=1
if count == 8:
result += chr(res)
count = 0
res = 0
else:
print 'Unexpected cp, exit!' # found '00' or '11', stop the script directly
break

code = code[2:]

with open('result.png','wb') as file_out:
file_out.write(result)
``````