hex_converter.pyw


SUBMITTED BY: Guest

DATE: Dec. 4, 2013, 2:50 a.m.

FORMAT: Python

SIZE: 5.1 kB

HITS: 1093

  1. #-------------------------------------------------------------------------------
  2. # Name: hex encoder, and decoder
  3. # Purpose: A small tool created to assisit in <<SQL INJECTION>>
  4. # And of course, for us to learn together.
  5. #-------------------------------------------------------------------------------
  6. import os,sys, base64
  7. from time import sleep
  8. from Tkinter import *
  9. import tkMessageBox
  10. def centerWindow(frame):
  11. w = 300; h=250
  12. frame.maxsize(300,250)
  13. #frame.minsize(300,220)
  14. sw = frame.winfo_screenwidth()
  15. sh = frame.winfo_screenheight()
  16. x = (sw-w)/2
  17. y = (sh-h)/2
  18. frame.geometry('%dx%d+%d+%d' % (w,h,x,y))
  19. def msg(title,message):
  20. tkMessageBox.showerror(title,message)
  21. def hexit():
  22. clear_box()
  23. txt = txt_box.get()
  24. if txt == '':
  25. msg('Error','Please Enter String to Convert')
  26. Entry.focus_set(txt_box)
  27. else:
  28. txt_box.delete(0,len(str(txt_box.get())))
  29. hexed = '0x'+txt.encode('hex')
  30. txt_box_display.insert(END,hexed)
  31. def clear_box():
  32. txt_box_display.delete(1.0,END)
  33. def dehexit():
  34. clear_box()
  35. hexed = txt_box.get()
  36. txt_box.delete(0,len(str(txt_box.get())))
  37. if hexed == '': msg('Error','Please Enter hex to convert')
  38. if '0x' in hexed: hexed = hexed.replace('0x','')
  39. try:
  40. dehexed = hexed.decode('hex')
  41. except TypeError:
  42. msg("Error","That didn't seem like hex")
  43. else:
  44. txt_box_display.insert(END,dehexed)
  45. def about():
  46. tkMessageBox.showinfo('About','This script is written by Anubis from MSF forum\n\
  47. This script supports conversion of string to hex and vice versa.\n\
  48. And conversion of md5 is also supported.\n\n\
  49. \t\tAnubis [MSF Moderator]')
  50. def base():
  51. clear_box()
  52. string = txt_box.get()
  53. txt_box.delete(0,len(str(txt_box.get())))
  54. if string == '': msg('Error','Please Enter String to convert')
  55. else:
  56. bas64 = base64.standard_b64encode(string)
  57. txt_box_display.insert(END,bas64)
  58. def b2s():
  59. clear_box()
  60. enc_string = txt_box.get()
  61. txt_box.delete(0,len(str(txt_box.get())))
  62. if enc_string == '': msg('Error','Please Enter String to convert')
  63. else:
  64. string = base64.standard_b64decode(enc_string)
  65. txt_box_display.insert(END,string)
  66. def sha():
  67. clear_box()
  68. from hashlib import sha1
  69. string = txt_box.get()
  70. txt_box.delete(0,len(str(txt_box.get())))
  71. if string == '': msg('Error','Please Enter String to convert')
  72. else:
  73. s = sha1()
  74. s.update(string)
  75. sha_hash = s.hexdigest()
  76. txt_box_display.insert(END,sha_hash)
  77. def md5it():
  78. clear_box()
  79. from hashlib import md5
  80. string = txt_box.get()
  81. txt_box.delete(0,len(str(txt_box.get())))
  82. if string == '': msg('Error','Please Enter string to convert')
  83. else:
  84. m = md5()
  85. m.update(string)
  86. md5_hash = m.hexdigest()
  87. txt_box_display.insert(END,md5_hash)
  88. def goodbye():
  89. import sys
  90. sys.exit()
  91. def gui():
  92. global txt_box,txt_box_display,root
  93. root = Tk()
  94. root.title('Hex-converter')
  95. lbl_welcome = Label(root,text="String to hash/hex converter")
  96. lbl_welcome.pack()
  97. centerWindow(root)
  98. txt_box = Entry(root,width='35')
  99. txt_box.pack()
  100. #btn_frame = LabelFrame(root)
  101. #btn_frame.pack()
  102. btn_str2hex = Button(root,text="Str2Hex",command=hexit,width='10')
  103. btn_str2hex.place(x=25,y=42)
  104. btn_hex2str = Button(root,text="Hex2Str",command=dehexit,width='10')
  105. btn_hex2str.place(x=25,y=67)
  106. btn_md5 = Button(root,text="Md5",command=md5it,width='10')
  107. btn_md5.place(x=195,y=42)
  108. btn_sha1 = Button(root,text="Sha1",command=sha,width='10')
  109. btn_sha1.place(x=195,y=67)
  110. btn_b64 = Button(root,text="Str2Base64",command=base,width='10')
  111. btn_b64.place(x=110,y=42)
  112. btn_b642str = Button(root,text="Base64toStr",command=b2s,width='10')
  113. btn_b642str.place(x=110,y=67)
  114. txt_box_display = Text(root)
  115. txt_box_display.config(width='33',height='6')
  116. txt_box_display.place(x=20,y=100)
  117. btn_quit = Button(root,text="QUIT",command=exit,width='15')
  118. btn_quit.place(x=90,y=210)
  119. menubar = Menu(root)
  120. help_menu = Menu(menubar,tearoff=0)
  121. help_menu.add_command(label="About",command=about)
  122. menubar.add_cascade(label="Help",menu=help_menu)
  123. root.config(menu=menubar)
  124. root.mainloop()
  125. if __name__ == '__main__':
  126. gui()

comments powered by Disqus