md5加密工具怎么用execel批量MD5加密工具 和 SM3批量加密工具




md5加密工具怎么用execel批量MD5加密工具 和 SM3批量加密工具

2022-07-20 21:30:25 网络知识 官方管理员

选择当前活动的execel单元格

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(1)

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(2)

打开MD5加密工具---因为不是美工,做工比较粗糙,请见谅,但是很实用!

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(3)

选择文件

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(4)

选择要加密的列

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(5)

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(6)

加密成功后结果如下:

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(7)

代码如下:

fromtkinter.filedialogimport*fromtkinterimport*importopenpyxlimporthashlibinfo={'path':[]}#字体样式_font=['Hack',20,'bold']_font_zi=['Hack',15,'bold']#每一个sheet固定的列defget_max_row(sheet):i=sheet.max_rowreal_max_row=0whilei>0:row_dict={i.valueforiinsheet[i]}ifrow_dict=={None}:i=i-1else:real_max_row=ibreakreturnreal_max_rowdefmake_app():app=Tk()Label(app,text='MD5加密工具',font=_font).pack()Label(app,text='文件名_选择加密的列,点击加密!',font=_font_zi).pack()Label(app,name="f_name",text='暂无文件',font=_font).pack()#fill=BOTH左右两边expand=True上下两边Listbox(app,name='listbox',bg='#f2f2f2').pack(fill=BOTH,expand=True)Button(app,name='open',text='打开excel文件',command=ui_getdata,font=_font_zi,   width=1).pack(fill=BOTH,expand=True)Button(app,name='compress_min',text='MD5加密小写',command=md5_min_T,font=_font_zi).pack(fill=BOTH,expand=True)Button(app,name='compress_max',text='MD5加密大写',command=md5_max_T,font=_font_zi).pack(fill=BOTH,expand=True)#初始框大小app.geometry('400x800')returnapp#ui界面交互tou_sheet=[]defui_getdata():f_name=askopenfilename()#赋值--路径添加到数据字典中info['path']=f_nameiff_name:app.children['f_name']['text']=f_name.split("/")[-1]#得到文件again_get_cloum(f_name)defagain_get_cloum(f_name):wookbook=openpyxl.load_workbook(f_name)book_sheet=wookbook.activelist_box=app.children['listbox']#缓存清空数据list_box.delete(0,END)tou_sheet.clear()foryyinrange(1,book_sheet.max_column+1):print(str(book_sheet.cell(1,yy).value))tou_sheet.append(book_sheet.cell(1,yy).value)list_box.insert(END,book_sheet.cell(1,yy).value)#加密功能defmd5_min_T():#重新得到最新的列#得到文件f_name_s=info['path']iff_name_s:wookbook=openpyxl.load_workbook(f_name_s)book_sheet=wookbook.activelistbox=app.children['listbox']colum=listbox.get(ACTIVE)cloum_num=tou_sheet.index(colum)+1book_sheet.insert_cols(cloum_num+1,1)#循环行forxinrange(2,get_max_row(book_sheet)+1):ifx==2:book_sheet.cell(1,cloum_num+1,book_sheet.cell(1,cloum_num).value+"_小写_加密成功")book_sheet.cell(x,cloum_num+1,md5_min(book_sheet.cell(x,cloum_num).value))wookbook.save(f_name_s)#得到文件again_get_cloum(info['path'])defmd5_max_T():#重新得到最新的列#得到文件f_name_s=info['path']iff_name_s:wookbook=openpyxl.load_workbook(f_name_s)book_sheet=wookbook.activelistbox=app.children['listbox']colum=listbox.get(ACTIVE)cloum_num=tou_sheet.index(colum)+1book_sheet.insert_cols(cloum_num+1,1)#循环行forxinrange(2,book_sheet.max_row+1):ifx==2:book_sheet.cell(1,cloum_num+1,book_sheet.cell(1,cloum_num).value+"_大写_加密成功")book_sheet.cell(x,cloum_num+1,md5_max(book_sheet.cell(x,cloum_num).value))wookbook.save(f_name_s)#得到文件again_get_cloum(info['path'])defmd5_max(s):returnhashlib.md5(s.encode()).hexdigest().upper()defmd5_min(s):returnhashlib.md5(s.encode()).hexdigest()#主显示框if__name__=='__main__':app=make_app()app.mainloop()

同理

SM3加密工具代码如下:

fromtkinter.filedialogimport*fromtkinterimport*importopenpyxlfrommathimportceilinfo={'path':[]}#字体样式_font=['Hack',20,'bold']_font_zi=['Hack',15,'bold']defmake_app():app=Tk()Label(app,text='SM3加密工具',font=_font).pack()Label(app,text='文件名_选择加密的列,点击加密!',font=_font_zi).pack()Label(app,name="f_name",text='暂无文件',font=_font).pack()#fill=BOTH左右两边expand=True上下两边Listbox(app,name='listbox',bg='#f2f2f2').pack(fill=BOTH,expand=True)Button(app,name='open',text='打开excel文件',command=ui_getdata,font=_font_zi,   width=1).pack(fill=BOTH,expand=True)Button(app,name='compress_min',text='SM3加密小写',command=sm3_min_T,font=_font_zi).pack(fill=BOTH,expand=True)Button(app,name='compress_max',text='SM3加密大写',command=sm3_max_T,font=_font_zi).pack(fill=BOTH,expand=True)#初始框大小app.geometry('400x800')returnapp#ui界面交互tou_sheet=[]defui_getdata():#ui_change('压缩')f_name=askopenfilename()#赋值--路径添加到数据字典中info['path']=f_nameiff_name:app.children['f_name']['text']=f_name.split("/")[-1]#得到文件again_get_cloum(f_name)defagain_get_cloum(f_name):wookbook=openpyxl.load_workbook(f_name)book_sheet=wookbook.activelist_box=app.children['listbox']#缓存清空数据list_box.delete(0,END)tou_sheet.clear()foryyinrange(1,book_sheet.max_column+1):print(str(book_sheet.cell(1,yy).value))tou_sheet.append(book_sheet.cell(1,yy).value)list_box.insert(END,book_sheet.cell(1,yy).value)#加密功能defsm3_min_T():#重新得到最新的列#得到文件f_name_s=info['path']iff_name_s:wookbook=openpyxl.load_workbook(f_name_s)book_sheet=wookbook.activelistbox=app.children['listbox']colum=listbox.get(ACTIVE)cloum_num=tou_sheet.index(colum)+1book_sheet.insert_cols(cloum_num+1,1)#循环行forxinrange(2,book_sheet.max_row+1):ifx==2:book_sheet.cell(1,cloum_num+1,book_sheet.cell(1,cloum_num).value+"_小写_加密成功")book_sheet.cell(x,cloum_num+1,sm3_min(book_sheet.cell(x,cloum_num).value))wookbook.save(f_name_s)#得到文件again_get_cloum(info['path'])defsm3_max_T():#重新得到最新的列#得到文件f_name_s=info['path']iff_name_s:wookbook=openpyxl.load_workbook(f_name_s)book_sheet=wookbook.activelistbox=app.children['listbox']colum=listbox.get(ACTIVE)cloum_num=tou_sheet.index(colum)+1book_sheet.insert_cols(cloum_num+1,1)#循环行forxinrange(2,book_sheet.max_row+1):ifx==2:book_sheet.cell(1,cloum_num+1,book_sheet.cell(1,cloum_num).value+"_大写_加密成功")book_sheet.cell(x,cloum_num+1,sm3_max(book_sheet.cell(x,cloum_num).value))wookbook.save(f_name_s)#得到文件again_get_cloum(info['path'])IV="7380166f4914b2b9172442d7da8a0600a96f30bc163138aae38dee4db0fb0e4e"IV=int(IV.replace("",""),16)a=[]foriinrange(0,8):a.append(0)a[i]=(IV>>((7-i)*32))&0xFFFFFFFFIV=adefout_hex(list1):foriinlist1:print("%08x"%i)print("\n")defrotate_left(a,k):k=k%32return((a<<k)&0xFFFFFFFF)|((a&0xFFFFFFFF)>>(32-k))T_j=[]foriinrange(0,16):T_j.append(0)T_j[i]=0x79cc4519foriinrange(16,64):T_j.append(0)T_j[i]=0x7a879d8adefFF_j(X,Y,Z,j):if0<=jandj<16:ret=X^Y^Zelif16<=jandj<64:ret=(X&Y)|(X&Z)|(Y&Z)returnretdefGG_j(X,Y,Z,j):if0<=jandj<16:ret=X^Y^Zelif16<=jandj<64:#ret=(X|Y)&((2**32-1-X)|Z)ret=(X&Y)|((~X)&Z)returnretdefP_0(X):returnX^(rotate_left(X,9))^(rotate_left(X,17))defP_1(X):returnX^(rotate_left(X,15))^(rotate_left(X,23))defCF(V_i,B_i):W=[]foriinrange(16):weight=0x1000000data=0forkinrange(i*4,(i+1)*4):data=data+B_i[k]*weightweight=int(weight/0x100)W.append(data)forjinrange(16,68):W.append(0)W[j]=P_1(W[j-16]^W[j-9]^(rotate_left(W[j-3],15)))^(rotate_left(W[j-13],7))^W[j-6]str1="%08x"%W[j]W_1=[]forjinrange(0,64):W_1.append(0)W_1[j]=W[j]^W[j+4]str1="%08x"%W_1[j]A,B,C,D,E,F,G,H=V_i"""print"00",out_hex([A,B,C,D,E,F,G,H])"""forjinrange(0,64):SS1=rotate_left(((rotate_left(A,12))+E+(rotate_left(T_j[j],j)))&0xFFFFFFFF,7)SS2=SS1^(rotate_left(A,12))TT1=(FF_j(A,B,C,j)+D+SS2+W_1[j])&0xFFFFFFFFTT2=(GG_j(E,F,G,j)+H+SS1+W[j])&0xFFFFFFFFD=CC=rotate_left(B,9)B=AA=TT1H=GG=rotate_left(F,19)F=EE=P_0(TT2)A=A&0xFFFFFFFFB=B&0xFFFFFFFFC=C&0xFFFFFFFFD=D&0xFFFFFFFFE=E&0xFFFFFFFFF=F&0xFFFFFFFFG=G&0xFFFFFFFFH=H&0xFFFFFFFF"""str1="%02d"%jifstr1[0]=="0":str1=''+str1[1:]printstr1,out_hex([A,B,C,D,E,F,G,H])"""V_i_1=[]V_i_1.append(A^V_i[0])V_i_1.append(B^V_i[1])V_i_1.append(C^V_i[2])V_i_1.append(D^V_i[3])V_i_1.append(E^V_i[4])V_i_1.append(F^V_i[5])V_i_1.append(G^V_i[6])V_i_1.append(H^V_i[7])returnV_i_1defhash_msg(msg):#print(msg)len1=len(msg)reserve1=len1%64msg.append(0x80)reserve1=reserve1+1#56-64,add64byterange_end=56ifreserve1>range_end:range_end=range_end+64foriinrange(reserve1,range_end):msg.append(0x00)bit_length=(len1)*8bit_length_str=[bit_length%0x100]foriinrange(7):bit_length=int(bit_length/0x100)bit_length_str.append(bit_length%0x100)foriinrange(8):msg.append(bit_length_str[7-i])#print(msg)group_count=round(len(msg)/64)B=[]foriinrange(0,group_count):B.append(msg[i*64:(i+1)*64])V=[]V.append(IV)foriinrange(0,group_count):V.append(CF(V[i],B[i]))y=V[i+1]result=""foriiny:result='%s%08x'%(result,i)returnresultdefstr2byte(msg):#字符串转换成byte数组ml=len(msg)msg_byte=[]msg_bytearray=msg.encode('utf-8')foriinrange(ml):msg_byte.append(msg_bytearray[i])returnmsg_bytedefbyte2str(msg):#byte数组转字符串ml=len(msg)str1=b""foriinrange(ml):str1+=b'%c'%msg[i]returnstr1.decode('utf-8')defhex2byte(msg):#16进制字符串转换成byte数组ml=len(msg)ifml%2!=0:msg='0'+msgml=int(len(msg)/2)msg_byte=[]foriinrange(ml):msg_byte.append(int(msg[i*2:i*2+2],16))returnmsg_bytedefbyte2hex(msg):#byte数组转换成16进制字符串ml=len(msg)hexstr=""foriinrange(ml):hexstr=hexstr+('%02x'%msg[i])returnhexstrdefHash_sm3(msg,Hexstr=0):if(Hexstr):msg_byte=hex2byte(msg)else:msg_byte=str2byte(msg)returnhash_msg(msg_byte)defKDF(Z,klen):#Z为16进制表示的比特串(str),klen为密钥长度(单位byte)klen=int(klen)ct=0x00000001rcnt=ceil(klen/32)Zin=hex2byte(Z)Ha=""foriinrange(rcnt):msg=Zin+hex2byte('%08x'%ct)#print(msg)Ha=Ha+hash_msg(msg)#print(Ha)ct+=1returnHa[0:klen*2]defsm3_max(s):returnHash_sm3(s).upper()defsm3_min(s):returnHash_sm3(s)#主显示框if__name__=='__main__':app=make_app()app.mainloop()

md5加密工具怎么用(execel批量MD5加密工具和SM3批量加密工具)(8)

希望对你有帮助

发表评论:

最近发表
网站分类
标签列表