?? t_des_dec.py
字號:
from M2Crypto import EVPimport cStringIOimport timedef test1(): key = '\xC8\xF6\xE4\x74\xC1\x55\x6E\x38\xF7\x75\xF6\xA9\x58\x80\x2C\x08' dec=0 for i in range(512): f=open('testv/msg%03d' % i,'rb') msg = f.read() f.close() f=open('testv/des%03d' % i,'rb') ctxt = f.read() f.close() cip = EVP.Cipher('des_ede_cbc',key,'\x00\x00\x00\x00\x00\x00\x00\x00',dec) pbuf = cStringIO.StringIO() cbuf = cStringIO.StringIO(ctxt) while 1: buf = cbuf.read() if not buf: break pbuf.write(cip.update(buf)) pbuf.write(cip.final()) ptxt = pbuf.getvalue() pbuf.close() cbuf.close() #print 'ptxt:',`ptxt` #print 'msg:',`msg` if ptxt ==msg: print '%d ok' % i else: print '%d failure' % idef test2(): key = '\xC8\xF6\xE4\x74\xC1\x55\x6E\x38\xF7\x75\xF6\xA9\x58\x80\x2C\x08' dec=0 ctxts=[] for i in range(512): f=open('testv/des%03d' % i,'rb') ctxts.append(f.read()) f.close() n=0 i=0 t1=time.time() print t1 while 1: cip = EVP.Cipher('des_ede_cbc',key,'\x00\x00\x00\x00\x00\x00\x00\x00',dec) pbuf = cStringIO.StringIO() cbuf = cStringIO.StringIO(ctxts[i]) while 1: buf = cbuf.read() if not buf: break pbuf.write(cip.update(buf)) pbuf.write(cip.final()) ctxt = pbuf.getvalue() pbuf.close() cbuf.close() n+=1 t2=time.time() if t2-t1 > 10: break i+=1 if i > 511: i=0 print t2 print 'passed:', t2-t1 print n return t2-t1,ndef loop_test2(): N=10 sum=0 for i in range(N): tx,n = test2() sum+=n time.sleep(10) print 'average:', sum/Nif __name__=='__main__': #test1() loop_test2()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -