今天老师给了我们这样一道题
“默克尔树有叶4个,自己定义叶子存放的数据,请计算默克尔树根的值。”
总的来说,还是得用tkinter
懒得自己搞死自己,决定”输入四个值”,直接一键输出后面所有的
对我这样的初学者来说,代码比较长,但分段做的话也不复杂,逻辑清晰就可以了。
下面是代码:
import tkinter
import hashlib
def mgbox1():
y1 = b1.get()
x1 = y1.encode()
hash_1 = hashlib.sha256(x1)
c1=hash_1.hexdigest()
listboxHash1.insert(0,c1)
y2 = b2.get()
x2 = y2.encode()
hash_2 = hashlib.sha256(x2)
c2 = hash_2.hexdigest()
listboxHash2.insert(0,c2)
y3 = b3.get()
x3 = y3.encode()
hash_3 = hashlib.sha256(x3)
c3 = hash_3.hexdigest()
listboxHash3.insert(0,c3)
y4 = b4.get()
x4 = y4.encode()
hash_4 = hashlib.sha256(x4)
c4 = hash_4.hexdigest()
listboxHash4.insert(0,c4)
c12 = c1+c2
h12 = c12.encode()
hash_12 = hashlib.sha256(h12)
w12=hash_12.hexdigest()
listboxHash5.insert(0,w12)
c34 = c3+c4
h34 = c34.encode()
hash_34 = hashlib.sha256(h34)
w34 = hash_34.hexdigest()
listboxHash6.insert(0, w34)
c1234 = w12+w34
u1234 = c1234.encode()
hash_1234 = hashlib.sha256(u1234)
w1234 = hash_1234.hexdigest()
listboxHash7.insert(0, w1234)
win1 = tkinter.Tk()
win1.title("哈希值生成器")
win1.geometry("700x400")
labelName1=tkinter.Label(win1,text='输入的值Tx1:',justify=tkinter.RIGHT,
anchor='e',width=80)
labelName1.place(x=20,y=5,width=80,height=20)
b1=tkinter.StringVar()
entryZhi1=tkinter.Entry(win1, width=20,textvariable=b1)
entryZhi1.place(x=100,y=5,width=300,height=20)
labelName2=tkinter.Label(win1,text='输入的值Tx2:',justify=tkinter.RIGHT,
anchor='e',width=80)
labelName2.place(x=20,y=30,width=80,height=20)
b2=tkinter.StringVar()
entryZhi2=tkinter.Entry(win1, width=20,textvariable=b2)
entryZhi2.place(x=100,y=30,width=300,height=20)
labelName3=tkinter.Label(win1,text='输入的值Tx3:',justify=tkinter.RIGHT,
anchor='e',width=80)
labelName3.place(x=20,y=55,width=80,height=20)
b3=tkinter.StringVar()
entryZhi3=tkinter.Entry(win1, width=20,textvariable=b3)
entryZhi3.place(x=100,y=55,width=300,height=20)
labelName4=tkinter.Label(win1,text='输入的值Tx4:',justify=tkinter.RIGHT,
anchor='e',width=80)
labelName4.place(x=20,y=80,width=80,height=20)
b4=tkinter.StringVar()
entryZhi4=tkinter.Entry(win1, width=20,textvariable=b4)
entryZhi4.place(x=100,y=80,width=300,height=20)
entryShuchu=tkinter.Button(win1,width=20,text="输出哈希值",command=mgbox1)
entryShuchu.place(x=20,y=105,width=80,height=20)
labelName5=tkinter.Label(win1,text='输出的哈希值H1:',justify=tkinter.RIGHT,
anchor='e',width=100)
labelName5.place(x=20,y=130,width=100,height=20)
labelName6=tkinter.Label(win1,text='输出的哈希值H2:',justify=tkinter.RIGHT,
anchor='e',width=100)
labelName6.place(x=20,y=155,width=100,height=20)
labelName7=tkinter.Label(win1,text='输出的哈希值H3:',justify=tkinter.RIGHT,
anchor='e',width=100)
labelName7.place(x=20,y=180,width=100,height=20)
labelName8=tkinter.Label(win1,text='输出的哈希值H4:',justify=tkinter.RIGHT,
anchor='e',width=100)
labelName8.place(x=20,y=205,width=100,height=20)
labelName9=tkinter.Label(win1,text='输出的哈希值H12:',justify=tkinter.RIGHT,
anchor='e',width=100)
labelName9.place(x=20,y=230,width=100,height=20)
labelName9=tkinter.Label(win1,text='输出的哈希值H34:',justify=tkinter.RIGHT,
anchor='e',width=100)
labelName9.place(x=20,y=255,width=100,height=20)
labelName10=tkinter.Label(win1,text='默克尔根H1234:',justify=tkinter.RIGHT,
anchor='e',width=100)
labelName10.place(x=20,y=280,width=100,height=20)
listboxHash1=tkinter.Listbox(win1,width=80)
listboxHash1.place(x=120,y=130,width=550,height=20)
listboxHash2=tkinter.Listbox(win1,width=80)
listboxHash2.place(x=120,y=155,width=550,height=20)
listboxHash3=tkinter.Listbox(win1,width=80)
listboxHash3.place(x=120,y=180,width=550,height=20)
listboxHash4=tkinter.Listbox(win1,width=80)
listboxHash4.place(x=120,y=205,width=550,height=20)
listboxHash5=tkinter.Listbox(win1,width=80)
listboxHash5.place(x=120,y=230,width=550,height=20)
listboxHash6=tkinter.Listbox(win1,width=80)
listboxHash6.place(x=120,y=255,width=550,height=20)
listboxHash7=tkinter.Listbox(win1,width=80)
listboxHash7.place(x=120,y=280,width=550,height=20)
win1.mainloop()
Original: https://blog.csdn.net/LZC19980621/article/details/127743791
Author: 学编程的驰驰
Title: python与区块链——默克尔树有叶4个,自己定义叶子存放的数据,请计算默克尔树根的值。
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/784573/
转载文章受原作者版权保护。转载请注明原作者出处!