Send Encrypted messages using python

Sending encrypted messages to remote computers has been made easy with Python and simple-crypt

simple-crypt is module that can be added to python making encryption an easy task.

Be sure you have simple-crypt installed in python modules.

receive.py

								
import os
from socket import *
from simplecrypt import decrypt
from config import port,key


host = ""
buf = 1024
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)
print "Waiting to receive messages..."
while True:
    (data, addr) = UDPSock.recvfrom(buf)
    msg = decrypt(key, data)
    print "Received message: " + msg
    if msg == "exit":
        break
UDPSock.close()
os._exit(0)

Go ahead and save that script then we can create a script to send encrypted messages to the machine running the receive code.

send.py

import os
from socket import *
from simplecrypt import encrypt
from config import host,port,key


addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
while True:
    data = raw_input("Enter message to send or type 'exit': ")
    ciphertext = encrypt(key, data)
    UDPSock.sendto(ciphertext, addr)
    if data == "exit":
        break
UDPSock.close()
os._exit(0)  	

Now that we are ready to send and receive encrypted messages lets create our config file

config.py

host = "XX.XX.XX.XX" # IP address of computer running receive.py
port = 13000  # Port number can be changed to communicate over any port

key = "Your_password"	

Enjoy