Advertisement
Programmin-in-Python

GUI Program to Hash String Values

Dec 21st, 2020 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.21 KB | None | 0 0
  1. # To Run the Program; You've to install pillow
  2.  
  3. import tkinter as tk, hashlib as hl
  4. from PIL import ImageTk, Image
  5. from os import urandom
  6. from tkinter import ttk
  7. from tkinter import messagebox as mb
  8.  
  9. global result
  10.  
  11. root = tk.Tk()
  12. root.title("Hasher")
  13. root.resizable(False, False)
  14.  
  15. # =============================== Variables ======================
  16. Input = tk.StringVar(root)
  17. Algorithm = tk.StringVar(root)
  18. AlgorithmList = ['blake2b', 'blake2s', 'md4', 'md5',
  19.                 'mdc2', 'ripemd160', 'sha1', 'sha224', 'sha256',
  20.                 'sha384', 'sha3_224', 'sha3_256', 'sha3_384',
  21.                 'sha3_512', 'sha512', 'shake_128', 'shake_256', 'sm3', 'whirlpool']
  22. salt = urandom(512)
  23. img = Image.open("Down Arrow.gif") # Image in GitHub : https://github.com/Programmin-in-Python/GUI-Hasher.git
  24. img = img.resize((150, 150), Image.ANTIALIAS)
  25. img = ImageTk.PhotoImage(img)
  26.  
  27. # ================================== Widgets ======================
  28. lblInput = tk.Label(root , font = ('arial' , 16 , 'bold') , \
  29.                                 text = 'Enter the String you want to hash : ' , bd = 7)
  30. lblInput.grid(row = 1 , column = 0 , sticky = 'n')
  31. txtInput = tk.Entry(root , font = ('arial' , 16 , 'bold') , \
  32.                             textvariable = Input , bd = 7 , insertwidth = 2)
  33. txtInput.grid(row = 1 , column = 1)
  34.  
  35. lblArrow = tk.Label(root, image=img)
  36. lblArrow.grid(row = 2 , column = 1 , sticky = 'n')
  37.  
  38. lblAlgorithm = tk.Label(root , font = ('arial' , 16 , 'bold') , \
  39.                                 text = 'Choose an Algorithm : ' , bd = 7)
  40. lblAlgorithm.grid(row = 3 , column = 0 , sticky = 'n')
  41. txtAlgorithm = ttk.Combobox(root , font = ('arial' , 16 , 'bold') , \
  42.                                 textvariable = Algorithm)
  43. txtAlgorithm['values'] = AlgorithmList
  44. txtAlgorithm.grid(row = 3 , column = 1)
  45.  
  46. lblArrow = tk.Label(root, image = img)
  47. lblArrow.grid(row = 4 , column = 1 , sticky = 'n')
  48.  
  49. lblResult = tk.Label(root , font = ('arial' , 16 , 'bold') , \
  50.                                 text = 'Result' , bd = 7)
  51. lblResult.grid(row = 5 , column = 0 , sticky = 'n')
  52. txtResult = tk.Text(root , width = 70 , height = 10 , font = ('arial' , 16 , 'bold'),
  53.                     foreground='black', background='white', state='disabled')
  54. txtResult.grid(row = 5 , column = 1)
  55.  
  56. #================================= Function =============================
  57. def Hash(event):
  58.     if Algorithm.get() == '': mb.showerror("Hasher", "You Haven't selected any Hashing Algorithm")
  59.     elif Algorithm.get() in AlgorithmList:
  60.         if Algorithm.get() == 'blake2b' :
  61.             result = hl.blake2b(Input.get().encode('utf-32')).hexdigest()
  62.  
  63.         elif Algorithm.get() == 'blake2s' :
  64.             result = hl.blake2s(Input.get().encode('utf-32')).hexdigest()
  65.  
  66.         elif Algorithm.get() == 'md5' :
  67.             result = hl.md5(Input.get().encode('utf-32')).hexdigest()
  68.  
  69.         elif Algorithm.get() == 'sha1' :
  70.             result = hl.sha1(Input.get().encode('utf-32')).hexdigest()
  71.  
  72.         elif Algorithm.get() == 'sha224' :
  73.             result = hl.sha224(Input.get().encode('utf-32')).hexdigest()
  74.  
  75.         elif Algorithm.get() == 'sha256' :
  76.             result = hl.sha256(Input.get().encode('utf-32')).hexdigest()
  77.  
  78.         elif Algorithm.get() == 'sha384' :
  79.             result = hl.sha384(Input.get().encode('utf-32')).hexdigest()
  80.  
  81.         elif Algorithm.get() == 'sha3_224' :
  82.             result = hl.sha3_224(Input.get().encode('utf-32')).hexdigest()
  83.  
  84.         elif Algorithm.get() == 'sha3_256' :
  85.             result = hl.sha3_256(Input.get().encode('utf-32')).hexdigest()
  86.  
  87.         elif Algorithm.get() == 'sha3_384' :
  88.             result = hl.sha3_384(Input.get().encode('utf-32')).hexdigest()
  89.  
  90.         elif Algorithm.get() == 'sha3_512' :
  91.             result = hl.sha3_512(Input.get().encode('utf-32')).hexdigest()
  92.  
  93.         elif Algorithm.get() == 'sha512' :
  94.             result = hl.sha512(Input.get().encode('utf-32')).hexdigest()
  95.  
  96.         elif Algorithm.get() == 'shake_128' :
  97.             result = hl.shake_128(Input.get().encode('utf-32')).hexdigest(128)
  98.  
  99.         elif Algorithm.get() == 'shake_256' :
  100.             result = hl.shake_256(Input.get().encode('utf-32')).hexdigest(128)
  101.  
  102.         else:
  103.             mod_input = Input.get().encode('utf-32')
  104.             result = hl.pbkdf2_hmac(Algorithm.get(), mod_input, salt, 10000).hex()
  105.  
  106.         txtResult.configure(state='normal')
  107.         txtResult.insert('1.0', result)
  108.     else: mb.showerror("Hasher", "Oops Sorry!!!\nThe Selected Algorithm is not there in my List...\nPlease Click the Drop-Down Box to see the list of Algorithms")
  109.  
  110. def Reset():
  111.     Input.set('')
  112.     Algorithm.set('')
  113.     txtResult.delete('1.0', 'end')
  114.     txtResult.configure(state='disabled')
  115.  
  116. # ============================== Buttons =================================
  117. btnReset = tk.Button(root, bd = 5, #bg='#ff0000',
  118.                     font = ('arial' , 16 , 'bold') , text = 'Reset' , command = Reset)
  119. btnReset.grid(row=7, column=0)
  120.  
  121. btnHash = tk.Button(root, bd = 5, #bg='#ff0000',
  122.                     font = ('arial' , 16 , 'bold') , text = 'Hash' , command = lambda : Hash("event"))
  123. btnHash.bind("<Return>", Hash)
  124. btnHash.grid(row = 7 , column = 1)
  125.  
  126. root.bind("<Return>", Hash)
  127. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement