def covertFile(infile, outfile, key): # Convert the key text to an integer try: enc_key = int(key) except ValueError: print("Error: The key %s should be an integer value!" % (key)) try: # Open the files with open(infile) as f_in: infile_content = f_in.readlines() except IOError: print("Unable to open %s" % (infile)) try: with open(outfile, "w") as f_out: for line in infile_content: out_line = ENC.encryptText(line, enc_key) f_out.writelines(out_line) except IOError: print("Unable to %s" % (outfile)) print("Conversion complete: %s" % (outfile)) print("Finish")
def covertfile(infile, outfile, key): try: enc_key = int(key) #key used in encrytion must be a integer except: print("Error: the key %s must be an integer" % (key)) else: try: with open(infile) as file_in: #with open() gives better syntax and exceptions handling, it automatically clean up infile_content = file_in.readlines() except: print("Unable to open %s" % (infile)) try: with open(outfile, 'w') as file_out: for line in infile_content: out_line = ENC.encryptText(line, enc_key) file_out.writelines(out_line) except: print("unable to open %s" % (outfile)) print("conversion complete : %s" % (outfile)) finally: print("Finish")
def covertFile(infile, outfile, key): #Convert the key text to an integer try: enc_key = int(key) except ValueError: print("Error: The key %s should be an integer value!" % (key)) else: try: #Open the files with open(infile) as f_in: infile_content = f_in.readlines() except IOError: print("Unable to open %s" % (infile)) try: with open(outfile, 'w') as f_out: for line in infile_content: out_line = ENC.encryptText(line, enc_key) f_out.writelines(out_line) except IOError: print("Unable to open %s" % (outfile)) print("Conversion complete: %s" % (outfile)) finally: print("Finish")
def convertFile(infile, outfile, key): #convert key yext to an integer try: enc_key = int(key) except ValueError: print("Error! The key %s should be an integer valiue!" %(key)) #code put on two lines else: try: #open file with open(infile) as f_in: infile_content = f_in.readlines() except IOError: print("Unable to open %s "%(infile)) try: with open(outfile,'w') as f_out: for line in infile_content: out_line=ENC.encryptText(line, enc_key) f_out.writelines(out_line) except IOError: print("Unable to open %s" %(outfile)) print("Conversion complite: %s" %(outfile)) finally: print("FINISH")
def decryptButton(): encryptvalue.set(ENC.encryptText(encryptvalue.get(), -keyvalue.get()))
#!/usr/bin/python3 #keypassing.py import encryptdecrypt as ENC KEY1 = 20 KEY2 = 50 print ("Please enter text to scramble:") #Get user input user_input = input() #Send message out encodedKEY1 = ENC.encryptText(user_input,KEY1) print ("USER1: Send message encrypted with KEY1 (KEY1): " + encodedKEY1) #Receiver encrypts the message again encodedKEY1KEY2 = ENC.encryptText(encodedKEY1,KEY2) print ("USER2: Encrypt with KEY2 & returns it (KEY1+KEY2): " + encodedKEY1KEY2) #Remove the original encoding encodedKEY2 = ENC.encryptText(encodedKEY1KEY2,-KEY1) print ("USER1: Removes KEY1 & returns with just KEY2 (KEY2): " + encodedKEY2) #Receiver removes their encryption message_result = ENC.encryptText(encodedKEY2,-KEY2) print ("USER2: Removes KEY2 & Message received: " + message_result) #End
#!/usr/bin/python3 #keypassing.py import encryptdecrypt as ENC KEY1 = 20 KEY2 = 50 print ("Please enter text to scramble:") #Get user input user_input = input() #Send message out encodeKEY1 = ENC.encryptText(user_input,KEY1) print ("USER1: Send message encrypted with KEY1 (KEY1): " + encodeKEY1) #Reciever encrypts the message again encodeKEY1KEY2 = ENC.encryptText(encodeKEY1,KEY2) print ("USER2: Encrypt with KEY2 & returns it (KEY1+KEY2): " + encodeKEY1KEY2) #Remove the original encoding encodeKEY2 = ENC.encryptText(encodeKEY1KEY2,-KEY1) print ("USER1: Removes KEY1 & returns it with just KEY2 (KEY2): " + encodeKEY2) #Reciever removes their encryption message_result = ENC.encryptText(encodeKEY2, -KEY2) print ("USER2: Removes KEY2 & Message received: " + message_result) #END
#!/usr/bin/python3 #keypassing.py import encryptdecrypt as ENC KEY1 = 20 KEY2 = 50 print("Please enter text to scramble: ") # Get user input user_input = input() # Send message out encodedKEY1 = ENC.encrypt.text(user_input, KEY1) print("USER1: Send message encrypted with KEY1 (KEY1): " + encodedKEY1) # Receiver encrypts the message again encodedKEY1KEY2 = ENC.encryptText(encodedKEY1, KEY2) print("USER2: encrypt with KEY2 & returns it (KEY1+KEY2): " + encodedKEY1KEY2) # Remove the original encoding encodedKEY2 = ENC.encryptText(encodedKEY1KEY2, -KEY1) print("USER1: removes KEY1 & returns with just KEY2 (KEY2)" + encodedKEY2) # Remove the encryption message_result = ENC.encryptText(encodedKEY2, -KEY2) print("USER2: removes the KEY2 & Message received: " + message_result)
#!/usr/bin/python3 #by three passing protocol,the receiver doesn't need to the key used by the sender. #Basically, the sender encrypted the message and send to receiver.at this stage #message has 2 layers of encryption. After receiving the message, #receiver encrypted the message by his own key and send back to the sender. Sender decrypted #the message and send to receiver again. NOw the message is only encrypted by receiver's key and #receiver can simply decrypt it. import encryptdecrypt as ENC key1 = int(input(print("please enter the sender's key"))) key2 = int(input(print("please enter the receiver's key"))) user_input = input(print("please enter the text")) encodekey1 = ENC.encryptText(user_input, key1) print("message encoded by sender is :" + encodekey1) encodekey1key2 = ENC.encryptText(encodekey1, key2) print("message encoded by receiver is :" + encodekey1key2) decodekey1 = ENC.encryptText(encodekey1key2, -key1) print("message decoded by sender is :" + decodekey1) decode = ENC.encryptText(decodekey1, -key2) print("The message received is:" + decode) #END