isefire

HashTool

Apr 12th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.04 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import Tkinter
  5. import tkFileDialog
  6. import tkMessageBox
  7. import hashlib
  8.  
  9.  
  10. class simpleapp_tk(Tkinter.Tk):
  11.     def __init__(self,parent):
  12.         Tkinter.Tk.__init__(self,parent)
  13.         self.parent = parent
  14.         self.bind('<Control-c>', self.copy)
  15.         self.bind('<Control-x>', self.cut)
  16.         self.bind('<Control-v>', self.paste)
  17.         self.bind('<Control-a>', self.selectall)
  18.         self.initialize()
  19.  
  20.     def initialize(self):
  21.         self.grid()
  22.        
  23.        
  24.         #######
  25.         #######
  26.         ####### TEXT VAR ENTRY
  27.         self.text1 = Tkinter.StringVar()
  28.         self.textbox = Tkinter.Text(self)
  29.         self.textbox.grid(column=0, row=0, sticky="EW")
  30.         #######
  31.         #######
  32.        
  33.        
  34.        
  35.         button = Tkinter.Button(self,text=u"Hash Away!", command=self.OnButtonClick)
  36.         button.grid(column=2,row=1)
  37.        
  38.         self.optionslist = ('ROT13','SHA-1','SHA-224','SHA-256','SHA-384','SHA-512','MD5')
  39.         self.var = Tkinter.StringVar(self)
  40.         self.var.set(self.optionslist[0])
  41.         self.optmenu = apply(Tkinter.OptionMenu,(self, self.var)+self.optionslist)
  42.         self.optmenu.grid(column=2,row=0)
  43.        
  44.        
  45.  
  46.         self.grid_columnconfigure(0,weight=1)
  47.         self.grid_rowconfigure(0,weight=1)
  48.         self.resizable(True,False)
  49.         self.update()
  50.         self.geometry(self.geometry())      
  51.         self.textbox.focus_set()
  52.         #self.entry.selection_range(0, Tkinter.END)
  53.        
  54.        
  55.        
  56.         ############
  57.         ############
  58.         ########### Menu
  59.         ###########
  60.         menubar = Tkinter.Menu(self)
  61.         filemenu = Tkinter.Menu(menubar, tearoff=0)
  62.         filemenu.add_command(label="New", command=self.Newbox)
  63.         filemenu.add_command(label="Open", command=self.Openfile)
  64.         filemenu.add_command(label="Save", command=self.SaveFile)
  65.         filemenu.add_command(label="Save as...", command=self.SaveFile)
  66.         filemenu.add_command(label="Close", command=self.Newbox)
  67.  
  68.         filemenu.add_separator()
  69.  
  70.         filemenu.add_command(label="Exit", command=self.quit)
  71.         menubar.add_cascade(label="File", menu=filemenu)
  72.         editmenu = Tkinter.Menu(menubar, tearoff=0)
  73.  
  74.         editmenu.add_command(label="Cut", command=self.cut)
  75.         editmenu.add_command(label="Copy", command=self.copy)
  76.         editmenu.add_command(label="Paste", command=self.paste)
  77.         editmenu.add_command(label="Delete", command=self.delete)
  78.         editmenu.add_command(label="Select All", command=self.selectall)
  79.  
  80.         menubar.add_cascade(label="Edit", menu=editmenu)
  81.         ###
  82.        
  83.         ###
  84.         aboutmenu = Tkinter.Menu(menubar, tearoff=0)
  85.         aboutmenu.add_command(label="About...", command=self.about)
  86.         menubar.add_cascade(label="About", menu=aboutmenu)
  87.  
  88.         self.config(menu=menubar)
  89.         ##########END MENU
  90.         ###########
  91.         ##########
  92.         ##########
  93.        
  94.        
  95.     def OnButtonClick(self):
  96.         if self.var.get() == 'ROT13':
  97.             self.rough1 = self.textbox.get("0.0",Tkinter.END)
  98.             self.textbox.delete("0.0", Tkinter.END)
  99.             self.textbox.insert('0.0',self.Rot13a(self.rough1).strip())
  100.         if self.var.get() == 'SHA-256':
  101.             self.rough1 = self.textbox.get("0.0",Tkinter.END)
  102.             self.textbox.delete("0.0", Tkinter.END)
  103.             self.textbox.insert('0.0',self.SHA256(self.rough1).strip())
  104.         if self.var.get() == 'SHA-512':
  105.             self.rough1 = self.textbox.get("0.0",Tkinter.END)
  106.             self.textbox.delete("0.0", Tkinter.END)
  107.             self.textbox.insert('0.0',self.SHA512(self.rough1).strip())
  108.         if self.var.get() == 'SHA-1':
  109.             self.rough1 = self.textbox.get("0.0",Tkinter.END)
  110.             self.textbox.delete("0.0", Tkinter.END)
  111.             self.textbox.insert('0.0',self.SHA1(self.rough1).strip())
  112.         if self.var.get() == 'SHA-224':
  113.             self.rough1 = self.textbox.get("0.0",Tkinter.END)
  114.             self.textbox.delete("0.0", Tkinter.END)
  115.             self.textbox.insert('0.0',self.SHA224(self.rough1).strip())
  116.         if self.var.get() == 'SHA-384':
  117.             self.rough1 = self.textbox.get("0.0",Tkinter.END)
  118.             self.textbox.delete("0.0", Tkinter.END)
  119.             self.textbox.insert('0.0',self.SHA384(self.rough1).strip())
  120.         if self.var.get() == 'MD5':
  121.             self.rough1 = self.textbox.get("0.0",Tkinter.END)
  122.             self.textbox.delete("0.0", Tkinter.END)
  123.             self.textbox.insert('0.0',self.MD5(self.rough1).strip())
  124.        
  125.        
  126.        
  127.     def Rot13a(self, text):
  128.         abc = list("abcdefghijklmnopqrstuvwxyz")
  129.         ABC = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  130.         lst = list(text)
  131.         newlst = []
  132.         for i in lst:
  133.             if i in abc:
  134.                 ind = abc.index(i)
  135.                 ind = (ind + 13)%26
  136.                 newlst.append(abc[ind])
  137.             elif i in ABC:
  138.                 ind = ABC.index(i)
  139.                 ind = (ind + 13)%26
  140.                 newlst.append(ABC[ind])
  141.             else:
  142.                 newlst.append(i)
  143.         txt = ""
  144.         text = txt.join(newlst)
  145.         return text
  146.    
  147.     def SHA256(self, string):
  148.         return hashlib.sha256(string).hexdigest()
  149.    
  150.     def SHA512(self, string):
  151.         return hashlib.sha512(string).hexdigest()
  152.    
  153.     def SHA1(self, string):
  154.         return hashlib.sha1(string).hexdigest()
  155.    
  156.     def MD5(self, string):
  157.         return hashlib.md5(string).hexdigest()
  158.        
  159.     def SHA224(self, string):
  160.         return hashlib.sha224(string).hexdigest()
  161.        
  162.     def SHA384(self, string):
  163.         return hashlib.sha384(string).hexdigest()
  164.  
  165.     def Newbox(self):
  166.         self.textbox.delete("0.0", Tkinter.END)
  167.        
  168.     def Openfile(self):
  169.         mask = \
  170.         [("Text and Python files","*.txt *.py *.pyw"),
  171.         ("HTML files","*.htm"),
  172.         ("All files","*.*")]
  173.         fin = tkFileDialog.askopenfile(initialdir='/', filetypes=mask, mode='r')
  174.         text = fin.read()
  175.         if text != None:
  176.             self.textbox.delete(0.0, Tkinter.END)
  177.             self.textbox.insert(Tkinter.END,text)
  178.    
  179.     def SaveFile(self):
  180.         """get a filename and save the text in the editor widget"""
  181.         # default extension is optional, here will add .txt if missing
  182.         fout = tkFileDialog.asksaveasfile(mode='w', defaultextension=".txt")
  183.         text2save = str(self.textbox.get(0.0,Tkinter.END))
  184.         fout.write(text2save)
  185.         fout.close()
  186.        
  187.     def copy(self, event):
  188.         self.clipboard_clear()
  189.         text = self.textbox.get("sel.first", "sel.last")
  190.         self.clipboard_append(text)
  191.    
  192.     def cut(self, event):
  193.         self.copy()
  194.         self.textbox.delete("sel.first", "sel.last")
  195.  
  196.     def paste(self):
  197.         text = self.selection_get(selection='CLIPBOARD')
  198.         self.textbox.insert('insert', text)    
  199.    
  200.     def delete(self):
  201.         self.textbox.delete("sel.first", "sel.last")   
  202.        
  203.     def selectall(self, event):
  204.         self.textbox.tag_add('sel', '1.0', 'end')  
  205.        
  206.     def about(self):
  207.         tkMessageBox.showinfo("About", """HashTool
  208.  
  209. Copyright 2014 [email protected]
  210.  
  211. This program is free software; you can redistribute it and/or modify
  212. it under the terms of the GNU General Public License as published by
  213. the Free Software Foundation; either version 2 of the License, or
  214. (at your option) any later version.
  215. This program is distributed in the hope that it will be useful,
  216. but WITHOUT ANY WARRANTY; without even the implied warranty of
  217. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  218. GNU General Public License for more details.
  219. You should have received a copy of the GNU General Public License
  220. along with this program; if not, write to the Free Software
  221. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  222. MA 02110-1301, USA.""")
  223.    
  224.     def donothing(self):
  225.         filewin = Tkinter.Toplevel(self)
  226.         button = Tkinter.Button(filewin, text="Do nothing button")
  227.         button.pack()
  228.  
  229. if __name__ == "__main__":
  230.     app = simpleapp_tk(None)
  231.     app.title('Hash Tool')
  232.     app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment