Esempio n. 1
0
def recv(t,key):
    newmess = server.recv(1024)
    print ("\nENCRYPTED MESSAGE FROM SERVER-> " + newmess)
    key = key[:16]
    decoded = newmess.decode("hex")
    ideaDecrypt = IDEA.new(key, IDEA.MODE_CTR, counter=lambda: key)
    dMsg = ideaDecrypt.decrypt(decoded)
    print ("\n**New Message From Server**  " + time.ctime(time.time()) + " : " + dMsg + "\n")
Esempio n. 2
0
def send(t, message, key):
    mess = message + " : "
    key = key[:16]
    whole = message + " : " + mess
    ideaEncrypt = IDEA.new(key, IDEA.MODE_CTR, counter=lambda: key)
    eMsg = ideaEncrypt.encrypt(whole)
    eMsg = eMsg.encode("hex").upper()
    if eMsg != "":
        print("ENCRYPTED MESSAGE SENT TO SERVER-> " + eMsg)
    s.send(eMsg)
Esempio n. 3
0
def send(t,name,key):
    mess = raw_input(name + " : ")
    key = key[:16]
    #merging the message and the name
    whole = name+" : "+mess
    ideaEncrypt = IDEA.new(key, IDEA.MODE_CTR, counter=lambda : key)
    eMsg = ideaEncrypt.encrypt(whole)
    #converting the encrypted message to HEXADECIMAL to readable
    eMsg = eMsg.encode("hex").upper()
    if eMsg != "":
        print ("ENCRYPTED MESSAGE TO SERVER-> "+eMsg)
    server.send(eMsg)
Esempio n. 4
0
    print("\n-----SESSION KEY-----\n" + en_digest)

    #encrypting session key and public key
    E = server_public_key.encrypt(encrypto, 16)
    print("\n-----ENCRYPTED PUBLIC KEY AND SESSION KEY-----\n" + str(E))
    print("\n-----HANDSHAKE COMPLETE-----")
    client.send(str(E))
    while True:
        #message from client
        newmess = client.recv(1024)
        #decoding the message from HEXADECIMAL to decrypt the ecrypted version of the message only
        decoded = newmess.decode("hex")
        #making en_digest(session_key) as the key
        key = en_digest[:16]
        print("\nENCRYPTED MESSAGE FROM CLIENT -> " + newmess)
        #decrypting message from the client
        ideaDecrypt = IDEA.new(key, IDEA.MODE_CTR, counter=lambda: key)
        dMsg = ideaDecrypt.decrypt(decoded)
        print("\n**New Message**  " + time.ctime(time.time()) + " > " + dMsg +
              "\n")
        mess = raw_input("\nMessage To Client -> ")
        if mess != "":
            ideaEncrypt = IDEA.new(key, IDEA.MODE_CTR, counter=lambda: key)
            eMsg = ideaEncrypt.encrypt(mess)
            eMsg = eMsg.encode("hex").upper()
            if eMsg != "":
                print("ENCRYPTED MESSAGE TO CLIENT-> " + eMsg)
            client.send(eMsg)
    client.close()
else:
    print("\n-----PUBLIC KEY HASH DOESNOT MATCH-----\n")