07.07.2023 Views

Implementing-cryptography-using-python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 ■ Mastering Cryptography Using Python 251

# no matter what, get the ECC shared key, only use it if the user

enables

clientSecret = get_dh_sharedkey()

print ("Welcome to Crypto-Chat! \n")

print ()

# sending loop

while True:

if sendUsingPrivate == True or sendUsingDH == True:

data = str(input("Enter secure message to send or type

'exit': ")).encode()

else:

data = str(input("Enter message to send or type 'exit': ")).

encode()

# determine if the user initiated a special command

result = ct.check_client_command(data)

# handle any custom commands

if data == b'exit':

break

if result == 0:

break

ciphertext = encrypt(data, sendUsingPrivate, sendUsingDH,

clientSecret)

if skipEncryption:

ciphertext = data;

skipEncryption = False;

# send the packet over UDP

UDPSock.sendto(ciphertext, addr)

# close UDP connection

UDPSock.close()

os._exit(0)

if __name__ == '__main__':

main()

Creating the Helper File

To keep the code as consistent as possible between each step in our design, I

will include various hooks that will be used later but, in this version, will not

be cryptographically functional. The helper file will be the primary focus on

most of our development tasks. Be sure to name this file ch9 _ crypto.py so

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!