def dec():
				
	n_USER=e2.get()				# GET THE USER INPUT n VALUE
	if n_USER == "Enter n":
		return
	if n_USER == "   Decryption cancelled   " :
		v.set("Enter n")
		return
	n_USR=int(n_USER)
	if n_USR == 0:
		e2.delete(0,END)
		v.set("Enter n")
		return

					# RETURNS THE PATH OF THE INTERMEDIATE						# TO READ THE ENCRYPTED DATA
	path_im=askopenfilename(title="Path of the Encrypted File",filetypes=[("Encrypted file","*.smt"),("pythonfiles","*.py")])
			#this function is imported from tkFileDialog
			#you can specify the filetypes of your choice 
			#there is an other function called LoadFileDialog which also
					# CHECKS IF DECRYPTION IS CANCELLED		
	if path_im == () :
		v.set("   Decryption cancelled   ")
		return
	fim=open(path_im,'r')
	fim.seek(0)
					
					# check the file if decryption possible
					# genuine intermediary file
					# encrypted using the same program
	binLen = 16
	sf_cd = 1010101010101010


	bin=int(fim.read(binLen))
	if bin != sf_cd :
		print "\nnot safe\n"
		return
	else :
		print "\nsafe\n"
	
						# RETREIVE INDEX TO FIND e
						# ( PUBLIC KEY )
	bin=int(fim.read(binLen))
	index = packages.b2a(bin)
	print "index is retrieved....."#,index
	
						# RETREIVE PHI VALUE
	bin=int(fim.read(binLen))
	PHI = packages.b2a(bin)
	print "PHI is retrieved......"#,PHI
	
						# RETREIVE e ( PUBLIC KEY )
	fim.seek(binLen*index)
	bin=int(fim.read(binLen))
	e = packages.b2a(bin)
	print "e is retrieved........"#,e
						# CALCULATE d ( PRIVATE KEY )
	d=packages.get_d(e,PHI)
	
	print "d is evaluated........"#,d
	
	
	fim.seek(binLen*24)			# REACH THE  n VALUE
	bin=int(fim.read(binLen))
	n = packages.b2a(bin)

					# RECEIVE THE USER INPUT n VALUE
		
					# CHECKS AUTHORISATION
	if n_USR == n :
					# RETURNS THE PATH OF THE OUTPUT FILE
					# TO GET THE DECRYPTED ACTUAL OUTPUT
		path_op=asksaveasfilename(title="Path of the decrypted File",filetypes=[("Text","*"),("Images","*.jpg"),("BitMapImage","*.bmp"),("pythonfiles","*.py")])
		
			#this function is imported from tkFileDialog
			#you can specify the filetypes of your choice 
			#there is an other function called LoadFileDialog which also 
			
		fop=open(path_op,'a')
		fop.seek(0)
		
		
		eoff = 1111111111111111
		
		
	
		bin=int(fim.read(binLen))
		while bin != eoff :
			C = packages.b2a(bin)
			M = packages.de_en(C,d,n)
			txt=chr(M)
			fop.write(txt)
			bin = int(fim.read(binLen))
	
		fim.close()
		fop.close()
		e2.delete(0,END)
		v.set("0")
	else :
		print "Wrong n entered"
		e2.delete(0,END)
		v.set("0")
fim.seek(0)

binLen = 16
sf_cd = 1010101010101010
# check the file if decryption possible
# genuine intermediary file
# encrypted using the same program
bin = int(fim.read(binLen))
if bin != sf_cd:
    print "\nnot safe\n"
else:
    print "\nsafe\n"


bin = int(fim.read(binLen))
index = packages.b2a(bin)
print "index is retrieved....."  # ,index


bin = int(fim.read(binLen))
PHI = packages.b2a(bin)
print "PHI is retrieved......"  # ,PHI


fim.seek(binLen * index)
bin = int(fim.read(binLen))
e = packages.b2a(bin)
print "e is retrieved........"  # ,e

d = packages.get_d(e, PHI)