⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_des_dec.py

📁 It is an experimental testing for python M2Crypto module. M2Crypto is not well document. User may no
💻 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 + -