python通过声音将文件内容隐藏,实现原理是将文件的内容分别插入到声音文件的不同位置中做为当次采样的数据,目前是对英文文本文档加解密
#!/usr/bin/env python # -*- coding: utf-8 -*-#http://blog.csdn.net/myhaspl #code:myhaspl@qq.com #将文件隐藏在声音之中import waveimport pylab as plimport numpy as npprint 'http://blog.csdn.net/myhaspl' print 'myhaspl@qq.com' print print 'working...' #编码print u'正在将文件编码进声音'print "generate wav data...."# 打开文档fo = wave.open(r"pltest.wav", "wb") file_object = open('test.txt')try: all_the_text = file_object.read( )finally: file_object.close( )wdata=map(ord,all_the_text)wdata=np.array(wdata)lwdata=len(wdata)# 设置波形参数#采样率framerate = 44100#声道数nchannels=2#每位宽度sampwidth=2#长度nframes =framerate*4#振幅base_amplitude = 200max_amplitude=128*base_amplitude#每个字符的间隔次数interval=(nframes-10)/lwdata#每周期样本数wave_data=np.zeros((nframes), dtype=np.short)count=0myrand=np.random.rand(nframes)for curpos in xrange(0,nframes): if curpos % interval==0 and count
本博客所有内容是原创,未经书面许可,严禁任何形式的转载
>>> runfile(r'K:\book_prog\audio_hy.py', wdir=r'K:\book_prog') http://blog.csdn.net/myhaspl myhaspl@qq.com working... 正在将文件编码进声音 generate wav data.... save new wav files.... 正在从声音解码文件 >>>
上图是对一段python代码文件的加密后形成的声音波形,加密的python代码文件内容如下:
#!/usr/bin/env python
#-*- coding: utf-8 -*- #code:myhaspl@qq.com import cv2 import numpy as np fn="test1.jpg" print 'http://blog.csdn.net/myhaspl' print 'myhaspl@qq.com' print print 'loading %s ...' % fn print 'working', img = cv2.imread(fn) w=img.shape[1] h=img.shape[0] sz1=w sz0=h EVENTS = ['CV_EVENT_MOUSEMOVE', 'CV_EVENT_LBUTTONDOWN', 'CV_EVENT_RBUTTONDOWN', 'CV_EVENT_MBUTTONDOWN', 'CV_EVENT_LBUTTONUP', 'CV_EVENT_RBUTTONUP', 'CV_EVENT_MBUTTONUP' , 'CV_EVENT_LBUTTONDBLCLK','CV_EVENT_RBUTTONDBLCLK','CV_EVENT_MBUTTONDBLCLK'] def callback_function(event,x,y,flag,param): global EVENTS global img if EVENTS[event]=='CV_EVENT_LBUTTONDOWN': print "(%d,%d):"%(y,x) print img[y,x,:] cv2.imshow('img', img) return def getdistance(color1,color2): return np.sqrt(sum((color1-color2)*(color1-color2))) cv2.namedWindow('img') cv2.setMouseCallback('img', callback_function) cv2.imshow('img', img) cv2.waitKey() cv2.destroyAllWindows()