def encrypt(username): print "-------------------------------------------" target_name = raw_input("Enter name of target : ") sql_command = "SELECT public_exp,modulus FROM main WHERE username LIKE '%s';" %target_name cursor.execute(sql_command) results = cursor.fetchall() exp = int(results[0][0]) modulus = int(results[0][1]) infilename = raw_input("Enter file to be encrypted : ") f = open(infilename, "r") text = "" for line in f.readlines(): text = text + line c = Toolkit.encrypt(text,exp,modulus) outfilename = raw_input("Enter name of the file to store the encrypted message : ") f = open(outfilename, "w", 0) f.write(c) print "-------------------------------------------" print "Done! Your Encrypted file is ready." print "-------------------------------------------" enter_into_log(username,target_name,infilename,outfilename) start_session(username)
def sign(username): print "-------------------------------------------" sql_command = "SELECT private_exp, modulus FROM main WHERE username like '%s'" %username cursor.execute(sql_command) result = cursor.fetchall() exp = int(result[0][0]) modulus = int(result[0][1]) infilename = raw_input("Enter name of file to be signed : ") f = open(infilename, "r") file_text = "" for line in f.readlines(): file_text = file_text + line fingerprint = Toolkit.get_fingerprint(file_text) c = Toolkit.encrypt(fingerprint,exp,modulus) outfilename = raw_input("Enter name of file to store the signature : ") f = open(outfilename, "w", 0) f.write(c) start_session(username)