Guest User

Untitled

a guest
Jun 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.33 KB | None | 0 0
  1. #########################################################################
  2. #
  3. # Swiss crypto tool is created purely in python.It supports
  4. # different hashing algorithm and different encryption algorithm
  5. # too.User can also send a secure email by encrypting their body
  6. # with private key using this tool.
  7. # This script is compatible with python2.7.
  8. # Before running this script please install pycrypto library and try
  9. # to resolve all dependencies issues.
  10. # Author : Sharad Kumar
  11. # Email : sharad.kumar@tutorialspoint.com
  12. #########################################################################
  13.  
  14.  
  15. import smtplib
  16. from email.MIMEMultipart import MIMEMultipart
  17. from email.MIMEText import MIMEText
  18. from Crypto.Cipher import ARC4
  19. from Crypto.Cipher import DES
  20. from Crypto.Cipher import AES
  21. from Tkinter import *
  22. import tkMessageBox
  23. import Tkinter
  24. import base64
  25. import hashlib
  26. import os
  27. import sys
  28.  
  29. #Functions for hashing,encryption and decryption.
  30. def clicked1():
  31. mEntry=Entry(root,textvariable=text1,text="Enter text to convert=").pack(side=TOP)
  32. global mtext
  33. mtext=text1.get()
  34. B4=Tkinter.Button(root,text="Convert",command=clicked1_convert)
  35. B4.pack(side=BOTTOM)
  36. def md5():
  37. md5L=Label(root,text="Enter data to convert:",fg="blue",font=("arial",15))
  38. md5L.pack()
  39. global mtext
  40. mEntry=Entry(root,textvariable=text1).pack(side=TOP)
  41. mtext=text1.get()
  42. B4=Tkinter.Button(root,text="Convert",command=md52)
  43. B4.pack(side=TOP)
  44. def md52():
  45. md5=hashlib.md5(mtext).hexdigest()
  46. md5L2=Label(root,text="MD5="+md5,bg="#F5DEB3",font=("arial",15))
  47. md5L2.pack()
  48. print "\nMD5:"+md5
  49.  
  50. def sha1():
  51. shaL=Label(root,text="Enter data to convert:",fg="blue",font=("arial",15))
  52. shaL.pack()
  53. global mtext
  54. mEntry=Entry(root,textvariable=text1).pack(side=TOP)
  55. mtext=text1.get()
  56. B4=Tkinter.Button(root,text="Convert",command=shaa1)
  57. B4.pack(side=TOP)
  58.  
  59. def shaa1():
  60. sha1=hashlib.sha1()
  61. sha1.update(mtext)
  62. shA1=sha1.hexdigest()
  63. SHA1L=Label(root,text="SHA1="+shA1,bg="#F5DEB3",font=("arial",15))
  64. SHA1L.pack()
  65. print "\nSHA1:"+shA1
  66.  
  67. def sha224():
  68. sha224=Label(root,text="Enter data to convert:",fg="blue",font=("arial",15))
  69. sha224.pack()
  70. global mtext
  71. mEntry=Entry(root,textvariable=text1).pack(side=TOP)
  72. mtext=text1.get()
  73. B4=Tkinter.Button(root,text="Convert",command=shA224)
  74. B4.pack(side=TOP)
  75.  
  76. def shA224():
  77. sha224=hashlib.sha224()
  78. sha224.update(mtext)
  79. shA224=sha224.hexdigest()
  80. SHA224L=Label(root,text="SHA224="+shA224,bg="#F5DEB3",font=("arial",15))
  81. SHA224L.pack()
  82. print '\nSHA224:'+shA224
  83.  
  84. def sha256():
  85. sha256=Label(root,text="Enter data to convert:",fg="blue",font=("arial",15))
  86. sha256.pack()
  87. global mtext
  88. mEntry=Entry(root,textvariable=text1).pack(side=TOP)
  89. mtext=text1.get()
  90. B4=Tkinter.Button(root,text="Convert",command=shA256)
  91. B4.pack(side=TOP)
  92.  
  93. def shA256():
  94. sha256=hashlib.sha256()
  95. sha256.update(mtext)
  96. shA256=sha256.hexdigest()
  97. SHA256L=Label(root,text="SHA256="+shA256,bg="#F5DEB3",font=("arial",15))
  98. SHA256L.pack()
  99. print "\nSHA256:"+shA256
  100.  
  101. def sha384():
  102. sha384=Label(root,text="Enter data to convert:",fg="blue",font=("arial",15))
  103. sha384.pack()
  104. global mtext
  105. mEntry=Entry(root,textvariable=text1).pack(side=TOP)
  106. mtext=text1.get()
  107. B4=Tkinter.Button(root,text="Convert",command=shA384)
  108. B4.pack(side=TOP)
  109. def shA384():
  110. sha384=hashlib.sha384()
  111. sha384.update(mtext)
  112. shA384=sha384.hexdigest()
  113. SHA384L=Label(root,text="SHA384="+shA384,bg="#F5DEB3",font=("arial",15))
  114. SHA384L.pack()
  115. print'\nSHA384:'+shA384
  116.  
  117. def sha512():
  118. sha512=Label(root,text="Enter data to convert:",fg="blue",font=("arial",15))
  119. sha512.pack()
  120. global mtext
  121. mEntry=Entry(root,textvariable=text1).pack(side=TOP)
  122. mtext=text1.get()
  123. B4=Tkinter.Button(root,text="Convert",command=shA512)
  124. B4.pack(side=TOP)
  125.  
  126. def shA512():
  127. sha512=hashlib.sha512()
  128. sha512.update(mtext)
  129. shA512=sha512.hexdigest()
  130. SHA512L=Label(root,text="SHA512="+shA512,bg="#F5DEB3",font=("arial",15))
  131. SHA512L.pack()
  132. print "\nSHA512:"+shA512
  133.  
  134.  
  135. def clicked2():
  136. text3=StringVar()
  137. label3=Label(root,textvariable=text3,bd="4",fg="brown",bg="grey")
  138. text3.set("Select Ciphers :")
  139. label3.pack()
  140. var = IntVar()
  141. R1 = Radiobutton(root, text="Block Cipher", variable=var, value=1,command=clicked3)
  142. R1.pack()
  143. R2 = Radiobutton(root, text="Stream Cipher", variable=var, value=2,command=clicked15)
  144. R2.pack()
  145.  
  146. def clicked3():
  147. text4=StringVar()
  148. label4=Label(root,textvariable=text4,bd="4",fg="brown",bg="grey")
  149. text4.set("Select Encryption:")
  150. label4.pack()
  151. R3 = Radiobutton(root, text="AES (Advanced Encryption Standard)", variable=var, value=1,command=clicked8)
  152. R3.pack()
  153. R4 = Radiobutton(root, text="DES (Data Encryption Standard)", variable=var, value=2,command=clicked4)
  154. R4.pack()
  155.  
  156. def clicked4():
  157. DESL=Label(root,text="Enter Data To Convert:",font=("arial",15))
  158. DESL.pack()
  159. global text3
  160. text3=StringVar()
  161. mEntry2=Entry(root,textvariable=text3,width=50).pack()
  162. B5=Tkinter.Button(root,text="OK",command=clicked5)
  163. B5.pack(side=BOTTOM)
  164.  
  165. def clicked5():
  166. global mText2
  167. mText2=(text3.get())
  168. print "Data to be converted :"+mText2
  169. BlockSize=8
  170. key=("12345678")
  171. des = DES.new(key, DES.MODE_ECB)
  172. cipher_text = (des.encrypt(mText2))
  173. bcipher_text=cipher_text.encode('hex')
  174. print "Key:"+key
  175. print "Encrypted Text:"+bcipher_text
  176. text5=StringVar()
  177. label5=Label(root,textvariable=text5,bd="4",fg="brown",bg="grey",font=("arial",15))
  178. text5.set("Key:"+key)
  179. label5.pack()
  180. text6=StringVar()
  181. label6=Label(root,textvariable=text6,bd="4",fg="brown",bg="grey",font=("arial",15))
  182. text6.set("Encrypted text:"+bcipher_text)
  183. label6.pack()
  184.  
  185. def clicked6():
  186. R5 = Radiobutton(root, text="AES (Advanced Encryption Standard)",value=0,command=clicked12)
  187. R5.pack()
  188. R6 = Radiobutton(root, text="DES (Data Encryption Standard)", value=1,command=clicked11)
  189. R6.pack()
  190. R20=Radiobutton(root,text="ARC4",value=2,command=clicked18)
  191. R20.pack()
  192.  
  193.  
  194.  
  195.  
  196. def clicked7():
  197. des2 = DES.new(text7.get(), DES.MODE_ECB)
  198. hdecrypt=text8.get()
  199. hexdecrypt=hdecrypt.decode('hex')
  200. decrypted=des2.decrypt(hexdecrypt)
  201. label7=Label(root,text="Decrypted_Data="+decrypted,fg="brown",bg="grey",font=("arial",15))
  202. label7.pack()
  203. print "Decrypted Data:"+decrypted
  204.  
  205. def clicked8():
  206. AESL=Label(root,text="Enter Text To Convert:")
  207. AESL.pack()
  208. global text9
  209. text9=StringVar()
  210. mEntry5=Entry(root,textvariable=text9,text="Enter data to be converted",fg="brown",bg="grey",width=50)
  211. mEntry5.pack()
  212. B8=Tkinter.Button(root,text="OK",command=clicked9)
  213. B8.pack()
  214.  
  215. def clicked9():
  216. global data
  217. data=text9.get()
  218. print "Data to be comverted:"+data
  219. B9=Tkinter.Button(root,text="Convert",command=clicked10(data))
  220. B9.pack()
  221.  
  222. def clicked10(privateInfo):
  223. BlockSize=32
  224. Padding='{'
  225. pad=lambda s:s+(BlockSize-len(s)%BlockSize)*Padding
  226. EncodeAES=lambda c,s:base64.b64encode(c.encrypt(pad(s)))
  227. Secret=os.urandom(BlockSize)
  228. HexSecret=Secret.encode('hex')
  229. label10=Label(root,text="Key="+HexSecret,fg="brown",bg="grey",font=("arial",15))
  230. label10.pack()
  231. print 'encrypted_key=='+HexSecret
  232. Cipher=AES.new(Secret)
  233. encoded=EncodeAES(Cipher,privateInfo)
  234. HexEncoded=encoded.encode('hex')
  235. label11=Label(root,text="Encrypted_Text="+HexEncoded,fg="brown",bg="grey",font=("arial",15))
  236. label11.pack()
  237. print 'Encrypted_String=='+HexEncoded
  238.  
  239.  
  240. def clicked11():
  241. DESD=Label(root,text="Enter Key To Decrypt")
  242. DESD.pack()
  243. global text7
  244. text7=StringVar()
  245. mEntry3=Entry(root,textvariable=text7,text="Enter Key here",fg="brown",bg="grey")
  246. mEntry3.pack()
  247. DESD2=Label(root,text="Enter Encrypted Text Here:",font=("arial",15))
  248. DESD2.pack()
  249. global text8
  250. text8=StringVar()
  251. mEntry4=Entry(root,textvariable=text8,text="Enter Encrypted Text Here:",fg="brown",bg="grey")
  252. mEntry4.pack()
  253. B7=Tkinter.Button(root,text="Decrypt",command=clicked7)
  254. B7.pack()
  255.  
  256. def clicked12():
  257. AESD=Label(root,text="Enter Key to decrypt:",font=("arial",15))
  258. AESD.pack()
  259. global text11
  260. text11=StringVar()
  261. global text12
  262. text12=StringVar()
  263. mEntry11=Entry(root,textvariable=text11,text="Enter Key Here")
  264. mEntry11.pack()
  265. AESD2=Label(root,text="Enter Data To Decrypt",font=("arial",15))
  266. AESD2.pack()
  267. mEntry12=Entry(root,textvariable=text12,text="Enter Text Here")
  268. mEntry12.pack()
  269. B11=Tkinter.Button(root,text="Ok",command=clicked13)
  270. B11.pack()
  271.  
  272. def clicked13():
  273. global key2
  274. global hexEncrypted_text2
  275. key3=text11.get()
  276. hexEncrypted_text2=text12.get()
  277. B13=Tkinter.Button(root,text="Decrypt",command=clicked14(key3,hexEncrypted_text2))
  278. B13.pack()
  279.  
  280. def clicked14(key2,hexEncrypted_text):
  281. Padding='{'
  282. DecodeAES=lambda c,e:c.decrypt(base64.b64decode(e)).rstrip(Padding)
  283. key4=key2.decode('hex')
  284. Cipher=AES.new(key4)
  285. encrypted_text=hexEncrypted_text.decode('hex')
  286. decoded=DecodeAES(Cipher,encrypted_text)
  287. label14=Label(root,text="Decrypted_Text="+decoded,fg="brown",bg="grey",font=("arial",15))
  288. label14.pack()
  289. print "Decrypted Data="+decoded
  290.  
  291. def clicked15():
  292. labeL15=Label(root,text="Select Encryption Algorithm :",fg="brown",bg="grey",font=("arial",15))
  293. labeL15.pack()
  294. R15 = Radiobutton(root, text="ARC4", variable=var, value=0,command=clicked16)
  295. R15.pack()
  296.  
  297. def clicked16():
  298. global text15
  299. global text16
  300. text15=StringVar()
  301. text16=StringVar()
  302. CLICK16=Label(root,text="Enter Key and Data To Convert:",font=("arial",15))
  303. CLICK16.pack()
  304. mEntry15=Entry(root,textvariable=text15,text="Enter Key:")
  305. mEntry15.pack()
  306. mEntry16=Entry(root,textvariable=text16,text="Enter Data")
  307. mEntry16.pack()
  308. B15=Tkinter.Button(root,text="Convert",command=clicked17)
  309. B15.pack()
  310.  
  311. def clicked17():
  312. key=text15.get()
  313. data15=text16.get()
  314. obj1 = ARC4.new(key)
  315. cipher_text15 = obj1.encrypt(data15)
  316. hex_cipher_text15=cipher_text15.encode('hex')
  317. label15=Label(root,text="Encrypted_Data="+hex_cipher_text15,fg="brown",bg="grey",font=("arial",15))
  318. label15.pack()
  319. print "Encrypted_Data="+hex_cipher_text15
  320. global text17
  321. global text18
  322.  
  323.  
  324.  
  325.  
  326. def clicked18():
  327. ARC4D=Label(root,text="Enter Key To Decrypt",font=("arial",15))
  328. ARC4D.pack()
  329. global text17
  330. global text18
  331. text17=StringVar()
  332. text18=StringVar()
  333. mEntry17=Entry(root,textvariable=text17,text="Enter Key")
  334. mEntry17.pack()
  335. ARC4D2=Label(root,text="Enter Encrypted Data:")
  336. ARC4D2.pack()
  337. mEntry18=Entry(root,textvariable=text18,text="Enter Data")
  338. mEntry18.pack()
  339. mButton17=Tkinter.Button(root,text="Ok",command=clicked19)
  340. mButton17.pack()
  341.  
  342. def clicked19():
  343. key16=text17.get()
  344. hex_data16=text18.get()
  345. data16=hex_data16.decode('hex')
  346. obj2 = ARC4.new(key16)
  347. decrypted16=obj2.decrypt(data16)
  348. label18=Label(root,text="Decrypted_Text="+decrypted16,fg="brown",bg="grey",font=("arial",15))
  349. label18.pack()
  350. print "Decrypted text="+decrypted16
  351.  
  352. def clicked20():
  353. global Semail
  354. global Temail
  355. global body
  356. global user_name
  357. global password
  358. global encrypted_body
  359. Semail=StringVar()
  360. Temail=StringVar()
  361. body=StringVar()
  362. user_name=StringVar()
  363. password=StringVar()
  364. encrypted_body=StringVar()
  365. EMAILL=Label(root,text="Enter your email:",font=("arial",18),bg="skyblue")
  366. EMAILL.pack()
  367. mEntryS=Entry(root,textvariable=Semail,text="Enter your Email")
  368. mEntryS.pack()
  369. TOEMAIL=Label(root,text="To Email=",bg="skyblue",font=("arial",18))
  370. TOEMAIL.pack()
  371. mEntryT=Entry(root,textvariable=Temail,text="Enter Reciever Email")
  372. mEntryT.pack()
  373. MESSAGE=Label(root,text="Enter your message=",bg="skyblue",font=("arial",18))
  374. MESSAGE.pack()
  375. mEntryB=Entry(root,textvariable=body,text="Enter your message")
  376. mEntryB.pack()
  377. USER=Label(root,text="Enter your User_Name=",bg="skyblue",font=("arial",18))
  378. USER.pack()
  379. mEntryU=Entry(root,textvariable=user_name,text="Enter you user_name")
  380. mEntryU.pack()
  381. PASS=Label(root,text="Enter your password=",bg="skyblue",font=("arial",18))
  382. PASS.pack()
  383. mEntryP=Entry(root,textvariable=password,text="Enter your Password",show="*")
  384. mEntryP.pack()
  385. B19=Tkinter.Button(root,text="Convert and Send",command=clicked21,font=("arial",13))
  386. B19.pack()
  387.  
  388. def clicked21():
  389. global msg
  390. msg=MIMEMultipart()
  391. global sa
  392. sa=Semail.get()
  393. msg['From']=sa
  394. global ta
  395. ta=Temail.get()
  396. msg['To']=ta
  397. msg['Subject']="Encrypted Email"
  398. uname=user_name.get()
  399. pwd=password.get()
  400. global privateBody
  401. privateBody=body.get()
  402. BlockSize2=32
  403. Padding='{'
  404. pad=lambda s:s+(BlockSize2-len(s)%BlockSize2)*Padding
  405. EncodeAES2=lambda c,s:base64.b64encode(c.encrypt(pad(s)))
  406. Secret2=os.urandom(BlockSize2)
  407. HexSecret2=Secret2.encode('hex')
  408. label20=Label(root,text="Key="+HexSecret2,fg="brown",bg="grey",font=("arial",15))
  409. label20.pack()
  410. print 'encrypted_key=='+HexSecret2
  411. Cipher2=AES.new(Secret2)
  412. encoded2=EncodeAES2(Cipher2,privateBody)
  413. HexEncoded2=encoded2.encode('hex')
  414. label21=Label(root,text="Encrypted_Text="+HexEncoded2,fg="brown",bg="grey",font=("arial",15))
  415. label21.pack()
  416. print 'Encrypted_String=='+HexEncoded2
  417. msg.attach(MIMEText(HexEncoded2))
  418. server=smtplib.SMTP('SMTP.gmail.com:587')
  419. server.ehlo()
  420. server.starttls()
  421. server.ehlo()
  422. server.login(uname,pwd)
  423. server.sendmail(sa,ta,msg.as_string())
  424. server.quit()
  425.  
  426.  
  427.  
  428. # graphical part
  429. root=Tk()
  430. root.title("Secure Mail")
  431. frame = Frame(root)
  432. frame.pack()
  433. frame.configure(bg="#F5DEB3")
  434. bottomframe = Frame(root)
  435. bottomframe.pack( side = BOTTOM )
  436. global text1
  437. text1=StringVar()
  438. var = StringVar()
  439. label = Label( frame, textvariable=var,bg="#F4A460",bd=5,width=80,height=3,fg="black",font=("arial",15))
  440. var.set("Secure Messaging System")
  441. label.pack(side=TOP)
  442. #B1 = Tkinter.Button(frame, text ="Hash Converter",pady=10,width=30,activebackground="pink",fg="Brown",command=clicked1)
  443. #B1.pack(side = LEFT)
  444. #B2 = Tkinter.Button(frame, text ="Encryption",pady=10,width=30,activebackground="pink",fg="Brown",command=clicked2)
  445. #B2.pack(side = LEFT)
  446. #B6 = Tkinter.Button(frame, text ="Decryption",pady=10,width=30,activebackground="pink",fg="Brown",command=clicked6)
  447. #B6.pack(side = LEFT)
  448. #B3 = Tkinter.Button(frame, text ="Secure Messaging",pady=10,width=30,activebackground="pink",fg="Brown",command=clicked20)
  449. #B3.pack(side = LEFT)
  450. mb=Menubutton ( frame, text="Hash Converter", relief=RAISED,width=35,height=3,bg="cyan")
  451. mb.menu = Menu ( mb, tearoff = 0 )
  452. mb["menu"] = mb.menu
  453. mb.menu.add_checkbutton ( label="MD5",command=md5 ,font=("arial",13))
  454. mb.menu.add_checkbutton ( label="SHA1",command=sha1,font=("arial",13))
  455. mb.menu.add_checkbutton ( label="SHA224",command=sha224,font=("arial",13))
  456. mb.menu.add_checkbutton ( label="SHA256",command=sha256,font=("arial",13))
  457. mb.menu.add_checkbutton ( label="SHA384",command=sha384,font=("arial",13))
  458. mb.menu.add_checkbutton ( label="SHA512",command=sha512,font=("arial",13))
  459. mb.pack(side=LEFT)
  460. mb2= Menubutton ( frame, text="Encryption", relief=RAISED,width=35,height=3,bg="cyan")
  461. mb2.menu = Menu ( mb2, tearoff = 0 )
  462. mb2["menu"] = mb2.menu
  463. mb2.menu.add_checkbutton ( label="Symmetric Encryption",command=clicked2)
  464. mb2.menu.add_checkbutton ( label="Assymetric Encryption")
  465. mb2.pack(side=LEFT)
  466. mb3= Menubutton ( frame, text="Decryption", relief=RAISED,width=35,height=3,bg="cyan")
  467. mb3.menu = Menu ( mb3, tearoff = 0 )
  468. mb3["menu"] = mb3.menu
  469. mb3.menu.add_checkbutton ( label="Symmetric Encryption",command=clicked6)
  470. mb3.menu.add_checkbutton ( label="Assymetric Encryption")
  471. mb3.pack(side=LEFT)
  472. mb4= Menubutton ( frame, text="Secure Email", relief=RAISED,width=35,height=3,bg="cyan")
  473. mb4.menu = Menu ( mb4, tearoff = 0 )
  474. mb4["menu"] = mb4.menu
  475. mb4.menu.add_checkbutton ( label="Symmetric Encryption",command=clicked20)
  476. mb4.menu.add_checkbutton ( label="Assymetric Encryption")
  477. mb4.pack(side=LEFT)
  478. root.mainloop()
  479. ##############################################################################################################################
Add Comment
Please, Sign In to add comment